使用cluster的时候,主进程可以向子进程发消息,通过worker.process.send 如果子进程向主进程发消息,该如何写呢???
官网实例如下: 父进程:
var cp = require('child_process'); var n = cp.fork(__dirname + '/sub.js'); n.on('message', function(m) { console.log('PARENT got message:', m); }); n.send({ hello: 'world' });
sub.js代码:
process.on('message', function(m) { console.log('CHILD got message:', m); }); process.send({ foo: 'bar' });
另外可以看一下我写的一个日志:http://cnodejs.org/topic/5190eb1263e9f8a542ae7b54
谢了,原来我发送写对了。接收写错了。
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
官网实例如下: 父进程:
sub.js代码:
另外可以看一下我写的一个日志:http://cnodejs.org/topic/5190eb1263e9f8a542ae7b54
谢了,原来我发送写对了。接收写错了。