Set the heartbeat timeout, heartbeat interval, and server timeout

I have a node.js server, and I use socket.io to exchange in real time between the server and clients. I noticed that if a mobile client (using the Ionic Framework) suddenly disconnects without notifying the server, the sockets live for hours (or forever). I read and looked at their documentation, and they have options like pingInterval, pingtimeout, heartbeat interval, heartbeat timeout, close timeout .

How to configure these values ​​on my server?

Which of these values ​​are out of date?

Here is my code.

 var express = require('express'); var app = express(); var server = require('http').createServer(app); var io = require('socket.io').listen(server); io.set('heartbeat interval', 5000); io.set('heartbeat timeout', 8000); io.set('timeout', 5000); io.on('connection', function(socket){...} 

None of this works. Any help or guidance is much appreciated.

PS: I connect the sockets of my collection when the client disconnects and it works fine when the clients tell the server that they want to disconnect gracefully.

+7
angularjs express ionic-framework
source share
1 answer

You should use pingTimeout as indicated here: https://github.com/Automattic/socket.io/issues/1900

Also do not forget to set the following parameters, as io.set does not work.

var io = require('socket.io')({ pingTimeout: 5000 })

More at: http://socket.io/docs/migrating-from-0-9/#configuration-differences

However, if this does not work, the odds of the ionic ones actually support the connection in the background. From the project about a year ago, I remember that I had several questions like this, and as a result the ionic disconnector hit hard when it went in the background.

+1
source share

All Articles