node.js , socket.io - disconnect event delay when internet connection dies

disconnect, node.js, socket.io

Solution

You have to use `pingTimeout` and `pingInterval` options on the server side to control this:

const io = require('socket.io').listen(server, {
  pingTimeout: 5000,
  pingInterval: 10000
});

- `pingTimeout` (`Number`): how many ms without a pong packet to consider the connection closed (`5000`)

- `pingInterval` (`Number`): how many ms before sending a new ping packet (`25000`)

More details about params: https://github.com/socketio/engine.io#methods-1

Problem

I notice that `socket.on('disconnect')` fires immediately when I close browser tab. But it fires approximately in a minute after internet connection dies. I'm using socket.io module. How can I fix this issue?

Original source

Related problems