forked from nteract/hydrogen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.coffee
57 lines (46 loc) · 1.45 KB
/
test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
fs = require 'fs'
zmq = require 'zmq'
_ = require 'lodash'
shell_socket = zmq.socket 'dealer'
io_socket = zmq.socket 'sub'
shell_socket.identity = 'dealer' + process.pid
io_socket.identity = 'sub' + process.pid
shell_socket.on 'message', (msg...) ->
console.log "new shell message"
_.forEach(msg,(item) ->
console.log "shell received:", item.toString('utf8'))
io_socket.on 'message', (msg...) ->
console.log "new IO message"
_.forEach(msg, (item) ->
console.log "io received:", item.toString('utf8'))
kernel_file_name = 'kernel-5666.json'
kernel_file_path = '/Users/will/Library/Jupyter/runtime/' + kernel_file_name
kernel_info = JSON.parse fs.readFileSync(kernel_file_path)
shell_port = kernel_info.shell_port
io_port = kernel_info.iopub_port
shell_socket.connect('tcp://127.0.0.1:' + shell_port)
io_socket.connect('tcp://127.0.0.1:' + io_port)
io_socket.subscribe('')
# console.log io_socket
header = JSON.stringify({
msg_id: 0,
username: "will",
session: "00000000-0000-0000-0000-000000000000",
msg_type: "execute_request",
version: "5.0"
})
shell_socket.send(
[
'<IDS|MSG>',
'',
header,
'{}',
'{}',
JSON.stringify({
code: "a - 4"
silent: false
store_history: true
user_expressions: {}
allow_stdin: false
})
])