有誰知道爲什麼我的套接字連接在使用xhr-polling時沒有關閉?這是我想要執行的服務器代碼,但在使用xhr-polling時不會觸發。套接字連接工作正常(我運行在帶有stunnel的清漆後面,因爲這是一個安全的套接字)。我嘗試在瀏覽器上手動發出斷開連接事件,但這不是我的最佳解決方案。用XHR輪詢關閉套接字連接
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版本。