Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get room's clients list in socket.io 1.0

I can get room's clients list with this code in socket.io 0.9.

io.sockets.clients(roomName) 

How can I do this in socket.io 1.0?

like image 467
uzimith Avatar asked May 25 '14 18:05

uzimith


People also ask

How do I find my socket IO client?

You can check the socket. connected property: var socket = io. connect(); console.

How many rooms can Socket.IO handle?

socket.io rooms are a lightweight data structure. They are simply an array of connections that are associated with that room. You can have as many as you want (within normal memory usage limits). There is no heavyweight thing that makes a room expensive in terms of resources.

What is the difference between Socket.IO and socket IO client?

socket-io. client is the code for the client-side implementation of socket.io. That code may be used either by a browser client or by a server process that is initiating a socket.io connection to some other server (thus playing the client-side role in a socket.io connection).

How many players can Socket.IO handle?

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


1 Answers

Consider this rather more complete answer linked in a comment above on the question: https://stackoverflow.com/a/24425207/1449799


The clients in a room can be found at

io.nsps[yourNamespace].adapter.rooms[roomName] 

This is an associative array with keys that are socket ids. In our case, we wanted to know the number of clients in a room, so we did Object.keys(io.nsps[yourNamespace].adapter.rooms[roomName]).length

In case you haven't seen/used namespaces (like this guy[me]), you can learn about them here http://socket.io/docs/rooms-and-namespaces/ (importantly: the default namespace is '/')

Updated (esp. for @Zettam):

checkout this repo to see this working: https://github.com/thegreatmichael/socket-io-clients

like image 149
Michael Avatar answered Oct 04 '22 04:10

Michael