Simple scenario:
socket = io.connect(...)
)socket.disconnect()
)It seems that once socket.io starts attempting to reconnect, it cannot be stopped anymore. I want step 4 to prevent step 6 from happening, but it doesn't. What do I have to call instead?
In the first case, the Socket will automatically try to reconnect, after a given delay.
close([callback]) Closes the socket.io server. The callback argument is optional and will be called when all connections are closed.
Explanation: The user logs in and after 60 seconds dropCheck is called. the dropCheck emits a ping and set a timmer of 4 seconds. the user handle the emited ping and responds with another ping.
on('connection', function(socket){ console. log('a user connected'); socket. on('disconnect', function(){ console. log('user disconnected'); }); });
You might want to handle the reconnection yourself.
// Disables the automatic reconnection
var socket = io.connect('http://server.com', {
reconnection: false
});
// Reconnects on disconnection
socket.on('disconnect', function(){
socket.connect(callback);
});
Note: old versions used reconnect
instead of reconnection
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With