如何创建socket.io多播组 [英] how to create socket.io multicast groups

查看:79
本文介绍了如何创建socket.io多播组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用socket.io模拟多播

I want to emulate multicast with socket.io

我习惯于BSD套接字,在其中将文件描述符保存在FD_SET中,并在事件循环中对其进行迭代以发送()或单独写入它们.如果我可以用javascript做类比,那我会很高兴:)

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:)

关于如何存储文件描述符",然后使用socket.io将send()数据分别发送到那些描述符的任何想法吗?

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

提前谢谢!

推荐答案

关于如何存储文件"的任何想法 描述符",然后分别 将send()数据发送到这些描述符 socket.io?

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

您可以存储socket.io id并将其用于将消息发送到各个连接.

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;

您可以在连接时将它们推到阵列上,并在断开连接时从阵列中删除(或使用redis).

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

这篇关于如何创建socket.io多播组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆