I am using socket io and child_process in a node js server, and I have a local webcrawler.py that I need to be exec'd per each socket 'connection' with each an individual client. Am I on the right track with the following scratch code? Also, on 'child.stdout.on', how do I program the python script to listen for the 'data' event? Or is the 'data' event when the script has finished running?io.on('connection', (socket) => { socket.on('start crawl', (crawlOptions) => { var child = exec(crawlOptions + ' python ./webcrawler.py', (error, stdout, stderr) => { child.stdout.on('data', (data) => { socket.emit('crawl data available', (JSON.parse(data))); }); }); }); });
Submitted May 05, 2017 at 05:05AM by judoka24
No comments:
Post a Comment