io.sockets.emit和广播之间有什么区别?

io.sockets.emit和socket.broadcast.emit有什么区别?广播只是向所有人发出但发送它的套接字吗?

似乎它们可以互换使用:

io.sockets.on('connection', function (socket) {

//these should do the same thing

io.sockets.emit('this', { receivers: 'everyone'});

socket.broadcast.emit('this', { receivers: 'everyone but socket'}); //emits to everyone but socket

socket.emit('this', { receivers: 'socket'}); //emits to socket

});

回答:

io.sockets.emit 将发送给所有客户

socket.broadcast.emit 会将消息发送给除新建连接以外的所有其他客户端

这篇Socket.IO

Wiki帖子将帮助所有人阅读以下问题:

以上是 io.sockets.emit和广播之间有什么区别? 的全部内容, 来源链接: utcz.com/qa/408926.html

回到顶部