Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.IO Connected User Count

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?

like image 711
imperium2335 Avatar asked Apr 23 '12 06:04

imperium2335


People also ask

How many users can Socket.IO handle?

Once you reboot your machine, you will now be able to happily go to 55k concurrent connections (per incoming IP).

Is Socket.IO popular?

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.

How do you get Socket.IO number of clients in a room?

Updated: Now, you can get number of clients in each room by numClients[socket. room] .

How do I monitor Socket.IO traffic?

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.


1 Answers

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

like image 112
Mody Avatar answered Oct 01 '22 18:10

Mody