List of connected clients username using socket io List of connected clients username using socket io express express

List of connected clients username using socket io


There are similar questions that will help you with this:

Socket.IO - how do I get a list of connected sockets/clients?

Create a list of Connected Clients using socket.io

My advice is to keep track yourself of the list of connected clients, because you never know when the internal API of Socket.IO may change. So on each connect add the client to an array (or to the database) and on each disconnect remove him.


In socket.io@2.3.0 you can use:

Object.keys(io.sockets).forEach((socketId) => {  const socket = io.sockets[socketId];})