Search code examples
socket.iodisconnect

Is there any way to disconnect a client connection of socket.io in the server.js?


I know the client part may use disconnect method to disconnect a client connection. but I can't find any way to disconnect from the server part.

socket.on('connection', function(client) {

    client.on('message', function(message) {
                var sessionId = message.disId;
        socket.disconnect(sessionId);//to disconnect another client
    });

});

Solution

  • The server can kick a particular client by using either of these methods:

    client._onDisconnect();

    (or)

    socket.clients[kickedUserSocketId].onDisconnect();

    Credit to SeanColombo on GitHub