how to create socket.io multicast groups

邮差的信 提交于 2019-12-06 07:39:17

问题


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!


回答1:


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


来源:https://stackoverflow.com/questions/6616922/how-to-create-socket-io-multicast-groups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!