Skip to content

SocketIO 3 -> Server API -> get socket objects by ID? #3804

Answered by darrachequesne
tgbv asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the namespace#sockets attribute:

for (const [id, socket] of io.of("/").sockets) {
  console.log(id, socket.handshake);
}

Please note that this Map contains only the socket instances on the current Socket.IO server, while the allSockets() method returns all socket IDs across multiple Socket.IO servers.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tgbv
Comment options

@darrachequesne
Comment options

@tgbv
Comment options

Answer selected by tgbv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants