有谁知道为什么我的套接字连接在使用 xhr-polling 时没有关闭?这是我想执行的服务器代码,但在使用 xhr-polling 时不会触发。套接字连接工作正常(我在 stunnel 的清漆后面运行,因为这是一个安全的套接字)。我尝试在浏览器卸载时手动发出断开连接事件,但这对我来说不是最佳解决方案。
client.on('disconnect', function () {
delete connected_clients[id];
console.log(' debug - ' + 'client ' + client.id + 'is disconnected');
console.log(' debug - ' + 'total number of connected clients is ' + Object.keys(connected_clients).length);
});
在我的客户端代码中,我像这样连接套接字:
socket = io.connect(BASE_URL, {
"sync disconnect on unload":true
});
我的服务器端设置是这样的:
io.enable('browser client minification'); // send minified client
io.enable('browser client etag'); // apply etag caching logic based on version number
io.enable('browser client gzip'); // gzip the file
io.set('log level', 3); // reduce logging
io.set('match origin protocol', true); // ssl support
io.set('sync disconnect on unload', true);
io.set('transports', [ // enable all transports (optional if you want flashsocket)
'xhr-polling',
'websocket',
'flashsocket',
'htmlfile',
'jsonp-polling'
]);
这是我在客户端退出浏览器时收到的调试消息
debug: xhr-polling closed due to exceeded duration
我正在使用带有节点 0.8.8 的 socket.io 版本 0.9.10。