3

I want to emulate multicast with socket.io

I am used to BSD sockets where you save file descriptors in FD_SET, and iterate over them in an event loop to send() or write to them individually. If I can do the analogy in javascript, I will be golden:)

Any ideas on how to store the "file descriptors" and then individually send() data to those descriptors with socket.io?

thanks in advance!

pyramation
  • 1,631
  • 4
  • 22
  • 35

1 Answers1

4

Any ideas on how to store the "file descriptors" and then individually send() data to those descriptors with socket.io?

You could store the socket.io id and use that to send messages to individual connections.

// v0.6.x
var sid = socket.sessionId;

// v0.7.x
var sid = socket.id;

You could push them onto an array on connection and remove from array on disconnection(or use redis for that).


But then again I think most times you are probably better of using namespace or rooms which you can read more information about on:

Alfred
  • 60,935
  • 33
  • 147
  • 186
  • if I use rooms, does socket.io automatically clean up empty rooms from memory? I am dynamically generating rooms which works well. Thanks again. – pyramation Jul 08 '11 at 19:37
  • thanks for the help. I posted another question I think you'd know off of the top : http://stackoverflow.com/questions/6631501/how-to-list-rooms-on-socket-io-nodejs-server – pyramation Jul 08 '11 at 23:15