-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.js
35 lines (28 loc) · 907 Bytes
/
start.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
var app=require('./app');
var server=require('http').Server(app);
var io=require('socket.io')(server);
var ser=server.listen(process.env.PORT || 8000, serverFunc);
function serverFunc(){
console.log(`Express is running on port ${server.address().port}`);
}
io.on('connection', transfer);
function transfer(socket){
socket.on('Image Data', (data)=>{
var spawn = require("child_process").spawn;
var pythonProcess = spawn('python',["testScript.py"]);
pythonProcess.stdin.write(data.data2);
pythonProcess.stdin.end();
pythonProcess.stdout.on('data', (data)=>{
console.log(data.toString());
//send result to client
socket.send(data.toString());
// socket.emit()
});
pythonProcess.stderr.on('data', (data)=>{
console.log(data.toString());
});
// pythonProcess.on('exit', (code)=>{
// console.log("Code:"+code);
// });
});
}