Sometimes, we want to send response to all clients except sender with Node.js socket.io.
In this article, we’ll look at how to send response to all clients except sender with Node.js socket.io.
For instance, we write
socket.broadcast.emit('message', "this is a test");
to send to all clients the 'this is a test'
message.
And we write
socket.broadcast.to('game').emit('message', 'nice game');
to send to all clients in the game room the message 'nice game'
except to the sender.
Conclusion
To send response to all clients except sender with Node.js socket.io, we call socket.broadcast.emit
to send to all clients except the sender.
And we use socket.broadcast.to
to send to all clients in a room except the sender.