In Socket.IO 0.7 you have a clients
method on the namespaces, this returns a array of all connected sockets.
API for no namespace:
var clients = io.sockets.clients();
var clients = io.sockets.clients('room'); // all users from room `room`
For a namespace
var clients = io.of('/chat').clients();
var clients = io.of('/chat').clients('room'); // all users from room `room`
Hopes this helps someone in the future
NOTE: This Solution ONLY works with version prior to 1.0
UPDATED 2020 Mar 06
From 1.x and above, please refer to this link: getting how many people are in a chat room in socket.io