force client disconnect from server with socket.io and nodejs
Is there any way to disconnect a client with SocketIO, and literally close the connection? So if someone is connected to my server, and I want to close the connection between them and my server, how would I go about doing that?
Solution 1:
Edit: This is now possible
You can now simply call socket.disconnect()
on the server side.
My original answer:
This is not possible yet.
If you need it as well, vote/comment on this issue.
Solution 2:
socket.disconnect()
can be used only on the client side, not on the server side.
Client.emit('disconnect')
triggers the disconnection event on the server, but does not effectively disconnect the client. The client is not aware of the disconnection.
So the question remain : how to force a client to disconnect from server side ?
Solution 3:
Any reason why you can't have the server emit a message to the client that makes it call the disconnect function?
On client:
socket.emit('forceDisconnect');
On Server:
socket.on('forceDisconnect', function(){
socket.disconnect();
});