Socket.io - disconnect event does not fire in xhr poll

In socket.io, the disconnect event does not fire when xpx polling is active. If I switch the transport to websites, it works fine, but in the xhr poll it doesn't work.

/* Basics */
var express = require('express'),
    app = express(),
    server = require('http').createServer(app),
    io = require('socket.io').listen(server);

server.listen(1337, null);

io.set('transports', ['xhr-polling']);

// routing
app.get('/', function (req, res) {
    res.sendfile("index.html");
    app.use(express.static(__dirname));
});

io.sockets.on('connection', function (socket) 
    socket.on('disconnect', function() {
        console.log('LOL');
    });
});

In the following code, the disconnect does not work, but if I delete the line -
io.set('transports', ['xhr-polling']);
It works fine, so why doesn't it work with xhr polling? but only with websockets?

How can i fix this? Am I missing something?

Thanks in Advance;)

+5
source share
2 answers

It is not possible to immediately detect disconnections using an XHR poll, as the client reconnects for each message.

Socket.io turns around this, setting an idle timeout on xhr-poll sockets.

: https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

. heartbeat interval. - 25 .

Websocket tcp- , socket.io , .

+1

, { "sync disconnect on unload": true} :

var socket = io.connect('http://yourServerDomain.com', {'sync disconnect on unload' : true});

.

+1

All Articles