Reputation: 738
Is there a way to close an idle client connection from the server side socket io implementation? Does socket.io cleans/closes idle connections from clients at a certain n time?
Upvotes: 2
Views: 2039
Reputation: 707178
socket.io is designed to be an always connected connection. It does not automatically disconnect itself after N time. In fact, it does the opposite. If it loses the connection, it automatically attempts to reconnect.
A server can disconnect a client by just calling:
socket.disconnect(true);
where socket
is the socket for a particular client. Of course socket.io clients will generally try to reconnect any time they lose the connection so it would probably be better to create your own message from the server that tells the client to disconnect. If the client disconnects on purpose, then it won't auto-reconnect.
On the client side, a client can call either of these:
socket.disconnect();
socket.close();
Is there a way to close an idle client connection from the server side socket io implementation?
You would have to invent your own definition for an idle connection and keep track of when a socket met that condition. When you determined it was idle, you could use one of the above methods to close the connection.
Does socket.io cleans/closes idle connections from clients at a certain n time?
No.
Upvotes: 3