Skip to content Skip to sidebar Skip to footer

Socket.io Takes A Long Time Before Triggering The Disconnect Event

I'm doing an HTML5 Game using node.js and socket.io I decided to host it on Heroku. Heroku isn't allowing the use of WebSockets, so I have to setup xhr-polling instead. (Socket-io

Solution 1:

It says here that you can configure the heartbeat. To properly configure it, you must adjust the heartbeat both on the server and the client side (which is given here).

Try lowering the heartbeat. It may solve your problem. On other note, appfog seems to support websockets.

Solution 2:

Just configure session auth and you can always know what client has connected. E.g.

io.set('authorization', function(handshakeData, ack) {
    var cookies = require(...);
    var signedCookies = parseCookies(cookies, secret);
    sessionStore.get(signedCookies['connect.sid'], function(err, sessionData) {
        handshakeData.session = sessionData || {};
        handshakeData.sid = signedCookies['connect.sid'] || null;
        ack(err, err ? false : true);
    });
});

Post a Comment for "Socket.io Takes A Long Time Before Triggering The Disconnect Event"