[英]What's difference between io.emit(…) and loop?
First of all, I hope you understand my poor english skill. 首先,希望您了解我的英语水平很差。
I'm developing a server using socket.io and server contains all client's 'socket' variable that given as parameter to 'connection'. 我正在使用socket.io开发服务器,并且服务器包含所有客户端的“ socket”变量,这些变量作为“连接”的参数给出。 and I want to broadcast 'message' without all functions of 'io' object.
我想广播“消息”而不使用“ io”对象的所有功能。 so I plan to implement broadcast function like that.
所以我打算实现这样的广播功能。
let socketList = [ ... ]; // <-- that array contains socket of client.
for (let i = 0; i < socketList.length; ++i)
socketList[i].emit(...);
but It makes no sence to me. 但这对我没有任何意义。 because I don't know that's same with io.emit function.
因为我不知道io.emit函数是不一样的。 so my question is: Is that code same with io.emit(...)?
所以我的问题是:io.emit(...)的代码是否相同?
That code and io.emit()
will do the same thing if all your clients really are in socketList
. 如果您的所有客户端确实都在
socketList
则该代码和io.emit()
将执行相同的socketList
。 If this is about performance and you don't have to do anything fancy like filtering out certain clients, I would go with io.emit()
, that way you won't need to keep your own socketList. 如果这是关于性能的,并且您不需要像过滤某些客户端那样花哨的事情,那么我将使用
io.emit()
,这样您就无需保留自己的socketList。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.