I finally got Socket.IO
to work properly, but I have encountered a strange problem.
I am not sure if this is the best way, but I am using:
io.sockets.clients().length
This returns the number of clients connected to my server. The problem is after a few connects and disconnects of users, the number starts to stay higher than it should be.
For instance, if I connect and ask my friends to, the number goes up which is correct. But when we start to disconnect and reconnect the number does not decrease.
I am running the Node.js
and Socket.IO
server on a VMware Ubuntu server.
Why is this or is there a better method for finding out how many people are connected to the server?
Once you reboot your machine, you will now be able to happily go to 55k concurrent connections (per incoming IP).
Socket.IO is quite popular, it is used by Microsoft Office, Yammer, Zendesk, Trello,. and numerous other organizations to build robust real-time systems. It one of the most powerful JavaScript frameworks on GitHub, and most depended-upon NPM (Node Package Manager) module.
Updated: Now, you can get number of clients in each room by numClients[socket. room] .
Use Monitor.io to observe connections and replay messages It shows a list of active Socket.io client connections for your application. You can use the monitoring interface to broadcast messages–either globally or to a specific client.
Just in case someone gets to this page while using socket.io version 1.0
You can get the connected clients count from
socketIO.engine.clientsCount
Need an answer and the above did not work for new version of socket.io
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