I am using socket.io with multiple nodes, socket.io-redis and nginx. I follow this guide: http://socket.io/docs/using-multiple-nodes/
I am trying to do: At a function (server site), I want to query by socketid that this socket is connected or disconnect
I tried io.of('namespace').connected[socketid]
, it only work for current process ( it mean that it can check for current process only).
Anyone can help me? Thanks for advance.
You can check the socket. connected property: var socket = io. connect(); console.
Once you reboot your machine, you will now be able to happily go to 55k concurrent connections (per incoming IP).
The socket. io-redis plugin uses the pub/sub client of the redis server to connect multiple socket.io instances.
How it works The Redis adapter relies on the Redis Pub/Sub mechanism. Every packet that is sent to multiple clients (e.g. io.to("room1"). emit() or socket.
How can I check socket is alive (connected) with socketid I tried namespace.connected[socketid], it only work for current process.
As you said, separate process means that the sockets are only registered on the process that they first connected to. You need to use socket.io-redis to connect all your nodes together, and what you can do is broadcast an event each time a client connects/disconnects, so that each node has an updated real-time list of all the clients.
Check out here
as mentioned above you should use socket.io-redis to get it work on multiple nodes.
var io = require('socket.io')(3000);
var redis = require('socket.io-redis');
io.adapter(redis({ host: 'localhost', port: 6379 }));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With