【发布时间】:2019-12-18 20:50:43
【问题描述】:
有什么区别:
socket.broadcast.to().emit()
和
socket.to().emit()
socket.to('game').emit('nice game', "let's play a game"); // sending to all clients in 'game' room except sender
然后在this tutorial blog 中说:
socket.broadcast.to('game').emit('message', 'nice game'); //sending to all clients in 'game' room(channel) except sender
socket.to('game').emit('message', 'enjoy the game'); //sending to sender client, only if they are in 'game' room(channel)
所以现在我真的很困惑。
其中一个解释有误吗?
仅当他们在“游戏”房间(频道)中时发送给发送者客户端是什么意思?这是否意味着如果是群聊,只有一个人(消息的发送者)会收到它?这是什么意思?
如果socket.io cheatsheet 是准确的,如果发送到“游戏”房间中除发件人之外的所有客户端通过调用以下方式完成,.broadcast.emit() 的目的是什么:@ 987654326@?
socket.broadcast.emit()是否仅用于发送到同一命名空间上的所有客户端(发送者除外)?但是,如果您想发送给特定房间中的所有客户(发件人除外),您使用socket.to().emit()而不是socket.broadcast.to().emit()?
谢谢。
【问题讨论】:
标签: sockets websocket socket.io