Websocket 向所有连接的客户端socket.io发送消息

Websocket 向所有连接的客户端socket.io发送消息,websocket,socket.io,Websocket,Socket.io,我使用下面的代码将消息发送到特定的客户端sessionId this.sockets[sessionId].json().send(消息) 但我不知道如何将消息发送到所有连接的客户端(浏览器),而不是发送到一个客户端。查看此备忘单 仅发送到发送方客户端 socket.emit('message', "this is a test"); 发送到所有客户端,包括发件人 io.emit('message', "this is a test"); io.in('game').emit('messag

我使用下面的代码将消息发送到特定的客户端sessionId

this.sockets[sessionId].json().send(消息)


但我不知道如何将消息发送到所有连接的客户端(浏览器),而不是发送到一个客户端。

查看此备忘单

仅发送到发送方客户端

socket.emit('message', "this is a test");
发送到所有客户端,包括发件人

io.emit('message', "this is a test");
io.in('game').emit('message', 'cool game');
io.of('myNamespace').emit('message', 'gg');
发送到除发件人以外的所有客户端

socket.broadcast.emit('message', "this is a test");
socket.broadcast.to('game').emit('message', 'nice game');
发送至“游戏”室(频道)中的所有客户端(发件人除外)

socket.broadcast.emit('message', "this is a test");
socket.broadcast.to('game').emit('message', 'nice game');
发送至“游戏”室(频道)中的所有客户端,包括发送者

io.emit('message', "this is a test");
io.in('game').emit('message', 'cool game');
io.of('myNamespace').emit('message', 'gg');
发送至发送方客户端,仅当他们在“游戏”室(频道)时

正在发送到命名空间“myNamespace”中的所有客户端,包括发件人

io.emit('message', "this is a test");
io.in('game').emit('message', 'cool game');
io.of('myNamespace').emit('message', 'gg');
发送到单个socketid

socket.broadcast.to(socketid).emit('message', 'for your eyes only');