How to update all clients using Socket.io?

Sometimes, we want to update all clients using Socket.io.

In this article, we’ll look at how to update all clients using Socket.io.

How to update all clients using Socket.io?

To update all clients using Socket.io, we call socket.broadcast.emit to broadcast to all sockets except the socket that starts it.

For instance, we write

socket.broadcast.emit('users_count', clients);

to call socket.broadcast.emit with the event name and the value we want to send.

Conclusion

To update all clients using Socket.io, we call socket.broadcast.emit to broadcast to all sockets except the socket that starts it.