node.js - Socket.IO - how do I get a list of connected sockets/clients? -


i'm trying list of sockets/clients connected.

io.sockets not return array, unfortunately.

i know keep own list using array, don't think optimal solution 2 reasons:

  1. redundancy. socket.io keeps copy of list.

  2. socket.io provides method set arbitrary field values clients (i.e: socket.set('nickname', 'superman')) i'd need keep these changes if maintain own list.

help?

in socket.io 0.7 have clients method on namespaces, returns array of connected sockets.

api no namespace:

var clients = io.sockets.clients(); var clients = io.sockets.clients('room'); // users room `room` 

for namespace

var clients = io.of('/chat').clients(); var clients = io.of('/chat').clients('room'); // users room `room` 

hopes helps in future

note: solution only works version prior 1.0


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -