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?
相关问题
- Django & node.js : throw arguments[1]; // Unhandle
- Socket.io Extra Placeholder Frame being sent
- how to Get all connected clients in socket.io
- websocket server, storing the data
- Socket.io Detect when client disconnects
相关文章
- Streaming music synchronously from a mp3 file via
- why is socket.id undefined in the browser
- Expressjs 4 route separation
- How to access websocket from controller or another
- Socket IO fails to connect within corporate networ
- Running socket.io on Shared Hosting
- Express - socket.io - reading session
- problems with socket.io on IE8 and 9
In my case I wanted to tear down the underlying connection in which case I had to call
socket.disconnect(true)
as you can see is needed from the source hereAny reason why you can't have the server emit a message to the client that makes it call the disconnect function?
On client:
On Server:
For those who found this on google - there is a solution for this right now:
Socket.disconnect()
kicks the client (server-side). No chance for the client to stay connected :)I'm using
client.emit('disconnect')
+client.removeAllListeners()
for connected client for ignore all events after disconnectEdit: 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.
Socket.io uses the EventEmitter pattern to disconnect/connect/check heartbeats so you could do.
Client.emit('disconnect');