Node js Socket Cluster get all sockets(clients) connected from server with socket id

558 Views Asked by At

Im working on nodejs project which has socketCluster module for bidirectional broadcasting. The problem is I want to disconnect specific socket using socket ID. What I have done so far is, I have the socket ID and I emit it to a listener in node server. Now I want to disconnect the socket using the socket ID. Can some one tell me how to fetch all the socket (clients) connected in the server and disconnect the socket using socket ID. For socket.io there are several references but for socketCluster there are only few, and they did not solve my problem.

1

There are 1 best solutions below

1
On

Most of cases everyone use User Id because of uniqueness so check that and pass that id on emit to below code

You can do console.log(room) or console.log(rooms) to check connected socket Ids

Use this code, you can disconnect particular socket.

io.sockets.connected[socketId].disconnect();