Node.js pass socket.io socket to a forked process

I am wondering if there is a way to pass socket.io socket into a forked process in node.js or restore socket.io socket in a forked process?

child = require("child_process").fork("worker.js")
io.sockets.on("connection", function(socket){
    child.send("socket", socket); //this definitely fails now
})
+5
source share
1 answer

Solution: Use Redis

I am sure you will be happy to learn about the existence of socket.io-redis

With it, you can send / receive events (share clients) between multiple instances of your code (processes or servers). Read more: socket.io-redis (Github Repo.)

With this you can scale:

  • vertically (increase in the number of threads per machine)
  •   ( "" ).

github

Node.JS client/server, Express.js, Socket.IO 1.x socket.io-redis .

, Socket.IO RealTime, . Redis () socket.io , .

0

All Articles