Socket.io disconnect client by id

后端 未结 1 1507
北荒
北荒 2021-01-01 03:22

I\'m new to nodejs and trying to write a chat room as so many people have. The chat consists of multiple rooms and clients. Commands such as /nick /join

相关标签:
1条回答
  • 2021-01-01 04:02

    The following code works with Socket.IO 1.0, however I'm not sure that this is the best solution:

    if (io.sockets.connected[socket.id]) {
        io.sockets.connected[socket.id].disconnect();
    }
    

    Update:

    With Socket.IO 0.9 the code would be slightly different:

    if (io.sockets.sockets[socket.id]) {
        io.sockets.sockets[socket.id].disconnect();
    }
    
    0 讨论(0)
提交回复
热议问题