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.
Asked
Active
Viewed 520 times
1 Answers
0
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();

Er Mitul Parmar
- 33
- 1
- 11
-
Thanks for your reply, actually for socket.io what you have done is correct, but i need it for socketCluster which is a similar module like socket.io – Vijay Wilson May 21 '18 at 05:33