Reputation: 2134
I have a node.js server and I am using socket.io for realtime communication between the server and clients. I have observed that if a mobile client (using Ionic Framework) disconnects suddenly, without letting the server know about it, the sockets are alive for hours (or forever). I have read and looked on their documentation and they have options like
pingInterval, pingtimeout, heartbeat interval, heartbeat timeout, close timeout
.
How do I configure these values on my server?
Which of these values have been deprecated?
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 these seem to work.
I am splicing sockets of my collection when a client disconnects and it works just fine when clients tell server that they want to disconnect gracefully.
Upvotes: 7
Views: 1944
Reputation: 2987
You have to use pingTimeout
as mentioned here:
https://github.com/Automattic/socket.io/issues/1900
Also make sure to set your options like the following, since io.set is gone.
var io = require('socket.io')({
pingTimeout: 5000
})
More at: http://socket.io/docs/migrating-from-0-9/#configuration-differences
However, if this doesn't work, chances are ionic is actually keeping the connection in the background. From a project around a year ago, I remember having multiple issues like this and ended up making ionic disconnect socket forcefully when it went in the background.
Upvotes: 1