socket.io: client-side disconnect is not detected
var socketio = io.connect(socketServer,
{rememberTransport: false,
'reconnect': true,
'reconnection delay': 500,
'max reconnection attempts': 10,
'secure': true});
socketio.on('disconnect', function() {
alert('client socketio disconnect!')
});
The alert shows up if I take down the Node server, but not if I turn off my wireless, or close my laptop and re-open it later. The connection is lost though. Is there a better way to detect disconnect on the client side? This is with the WebSockets transport.
About this issue
- Original URL
- State: closed
- Created 13 years ago
- Reactions: 23
- Comments: 61 (10 by maintainers)
Commits related to this issue
- Implement client side heartbeat checks Fixes https://github.com/LearnBoost/socket.io/issues/635 — committed to mpaf/pong-AI by felixge 12 years ago
- Implement client side heartbeat checks Fixes https://github.com/LearnBoost/socket.io/issues/635 — committed to sunrise30/socket.io-client by sunrise30 12 years ago
Please re-open this ticket, since it’s not yet fixed! I’was looking at the file: https://github.com/socketio/socket.io-client/blob/master/lib/manager.js to figure out if there is any option for that, and I found
timeoutwhich is 20 second by default. But when I’ve tried to change it to 4 sec, it just didn’t work at all.I was able to fix this issue by adjusting the
heartbeat timeoutandheartbeat intervalsettings on the server, which I believe dictates the client side heartbeat. For example, if you’d like the client to trigger a disconnect after it does two heartbeats every 4 seconds and doesn’t get a response then you would configure like the following.io.set('heartbeat timeout', 10) io.set('heartbeat interval', 4)I just went through all of my connection settings again and I must have had a typo somewhere. When I set
pingTimeoutandpingIntervalon the server, the client appears to respect that even in Chrome. If anyone else is having problems and wants to test this, it helps to setlocalStorage.debug = 'engine.io-client:socket'in your browser. This will make ping/pong messages show in the console.hi i use this solution and fine for me var io = require(‘socket.io’)(http, {‘pingInterval’: 2000, ‘pingTimeout’: 5000}); http://stackoverflow.com/a/31787022/2818627
Hi guys,
Any luck with this? I am also facing the same issue.
Yep, I believe so. Looks like everything is working as expected.
Hi, Still not found a good solution for this issue. I turned off my wifi connection set browser mode to offline still disconnect event of socket.io was not raised. was it due to local connection?
Regards, Suhas
Agreed - this is still a problem for me also