将socket.io套接字传递给派生的节点子进程

时间:2018-07-05 05:21:41

标签: node.js express socket.io centos7 child-process

  • Centos:7
  • 节点:8.9.4
  • Socket.io:2.1.1
  • 快递:4.16.3

我想将SOCKET对象传递给我派生的Node子进程,但是出现错误。 有人可以解释为什么我当前的代码出错,如何将套接字发送到子进程吗?

//-------------[parent.js]-------------
var child = cp.fork('../child/child.js', ['Started Child!']);

_IO.on('connection', function(_Socket){

        child.send(_Socket); // TypeError : Converting circular structure to JSON
        child.send('socket', _Socket); // TypeError : [ERR_INVALID_HANDLE_TYPE]
}); 

//-------------[child.js]-------------
process.on('message', function(socket){
        console.log(typeof socket);
});

//-------------[OR]-------------

process.on('message', function(msg, socket){
        console.log(msg);
        console.log(typeof socket);
});

0 个答案:

没有答案