Socket.io “connection” event fired on every client heartbeat?

后端 未结 2 2204
陌清茗
陌清茗 2021-01-07 02:11

I have a basic Socket.io server setup like this:

var server = express.createServer().listen(port);
    this.io = socketIO.listen(server);

this.io.sockets.on         


        
2条回答
  •  梦谈多话
    2021-01-07 03:10

    Found the problem. I had my xhr "polling duration" set to heroku's suggested 10s like so:

    io.set("polling duration", 10);
    

    Which means that the client only makes a new xhr request every 10 seconds (as soon as the previous request returns). At the same time I had the "close timeout" set to 3 seconds:

    io.set("close timeout", 3);
    

    Which means if the server does not hear from the client within 3 seconds since its last request it closes the connection, hence the continuous 'disconnect/connection' events being fired.

    The solution was to set the close timeout higher than the polling duration. It would seem that the "heartbeat interval" is not relevant for xhr connections.

提交回复
热议问题