how to create socket.io multicast groups
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!
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:
- http://socket.io/#how-to-use
- https://github.com/LearnBoost/Socket.IO/wiki
精彩评论