SocketIO: disconnect client by socket id?

后端 未结 2 412
难免孤独
难免孤独 2021-01-14 23:50

I have a Node server with SocketIO and several connections. How is it possible to disconnect an existing socket based on its ID? There are rooms, an admin in each room and o

相关标签:
2条回答
  • 2021-01-15 00:30

    You can hash it in a JSON object

    See Socket#id:String

    var json = {}; ... //create your serversocket, accept a connection json[Socket.id] = Socket

    0 讨论(0)
  • 2021-01-15 00:40

    On server side you can access io.sockets.connected which holds all connected sockets:

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

    0 讨论(0)
提交回复
热议问题