你見過this?
var io = require('socket.io').listen(80);
io.set('close timeout', 60);
io.set('heartbeat timeout', 60);
也許像
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);
編輯:這是一個長鏡頭,但:
var app = require('express')();
var server = require('http').Server(app);
server['close timeout'] = 60;
var io = require('socket.io')(server);
server.listen(port, ip);
編輯: 發現這對socket.io docs:
// pass a server and the `serveClient` option
var io = require('socket.io')(http, { serveClient: false });
那麼,這是怎麼回事?
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server, { 'close timeout': 60});
server.listen(port, ip);
另一個編輯: 再次在docs:
傳遞給socket.io總是傳遞給 時生成的engine.io服務器相同的選項。作爲參考請參閱engine.io options。
pingTimeout (Number): how many ms without a pong packet to consider the connection closed (60000)
你可以試試這個?
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server, { pingTimeout: 60000});
server.listen(port, ip);
io.set()自socket.io 1.0開始已棄用,我無法使用 – user3146857 2014-10-20 14:13:08
'server ['close timeout'] = 60;''這不是一個壞主意,但它不起作用。我想知道如果我正確地做事 - '' – user3146857 2014-10-20 14:31:14
我已經嘗試過'var io = require('socket.io')(server,{'close timeout':60});' =>沒有工作:(這很奇怪,這就是爲什麼我想知道如果我做錯了什麼... – user3146857 2014-10-20 14:52:42