-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabserver.js
35 lines (28 loc) · 838 Bytes
/
fabserver.js
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
//
// fabnetserver.js
//
//
var server_port = '1234'
var client_address = '127.0.0.1'
console.log("listening for connections from "+client_address+" on "+server_port)
var server = {}
var WebSocketServer = require('ws').Server
wss = new WebSocketServer({port:server_port})
function worker(ws,arg) {
var child_process = require('child_process')
console.log("python fabnet_plotter.py '"+arg+"'")
child_process.exec("python fabnet_plotter.py '"+arg+"'",function(err,stdout,stderr) {
ws.send(stdout)
})
}
server.worker = worker;
wss.on('connection',function(ws) {
if (ws._socket.remoteAddress != client_address) {
console.log("error: client address doesn't match")
return
}
ws.on('message',function(msg) {
//console.log('message: '+msg);
server.worker(ws,msg);
})
})