Official method:
io.sockets.clients().forEach(function (socket) { .. });
Or filter by room:
io.sockets.clients('roomname') .. same as above ..
This is stated above, because the internal data structure of socket.io can always be changed and could potentially damage all your code with future updates. You are much less at risk when using this official method.
source share