how to get socket.io number of clients in room?
问题 my socket.io version 1.3.5 I want to get number of clients in particular room. This is my code. socket.on('create or join', function (numClients, room) { socket.join(room); }); I use this code for get clients in room : console.log('Number of clients',io.sockets.clients(room)); 回答1: To get the number of clients in a room you can do the following: function NumClientsInRoom(namespace, room) { var clients = io.nsps[namespace].adapter.rooms[room]; return Object.keys(clients).length; } This