user3146857
user3146857

Reputation: 31

Socket.io 1.0 : configure close timeout

How can I configure the option 'close timeout' with the code below ?

 var app = require('express')();
 var server = require('http').Server(app);
 var io = require('socket.io')(server);
 ...
 server.listen(port, ip);     

I read the doc about socket.io and I found that :

 var socket = require('socket.io')({
     // options go here
 });

but I can't add options because I'm using the server variable.

Thanks.

Upvotes: 3

Views: 5284

Answers (2)

xinyuan
xinyuan

Reputation: 1

According to the latest version. { pingTimeout: 60000} works fine for me.

And io.set('heartbeat timeout', 10) works as well, but set will be removed in the future.

Upvotes: 0

Bruno Camarneiro
Bruno Camarneiro

Reputation: 555

Have you seen this ?

var io = require('socket.io').listen(80);
io.set('close timeout', 60);
io.set('heartbeat timeout', 60);

Maybe something like

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
io.set('close timeout', 60);
server.listen(port, ip); 

Edit: This is a long shot but:

var app = require('express')();
var server = require('http').Server(app);
server['close timeout'] = 60;
var io = require('socket.io')(server);
server.listen(port, ip); 

Edit: Found this on socket.io docs:

// pass a server and the `serveClient` option
var io = require('socket.io')(http, { serveClient: false });

So, what about this?

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server, { 'close timeout': 60});
server.listen(port, ip); 

Yet another Edit: In docs again:

The same options passed to socket.io are always passed to the engine.io Server that gets created. See engine.io options as reference.

pingTimeout (Number): how many ms without a pong packet to consider the connection closed (60000)

Can you try this?

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server, { pingTimeout: 60000});
server.listen(port, ip); 

Upvotes: 2

Related Questions