3

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?

Paramore
  • 1,313
  • 2
  • 19
  • 37

1 Answers1

13

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

Footniko
  • 2,682
  • 2
  • 27
  • 36
  • great! how is it connected with engine.io? isn't engine.io built over socket.io? i can't find any documentation for socket.io. again thanks, that helped me very much! – Dima Gimburg Sep 16 '15 at 11:29
  • 1
    You welcome. Engine.io is a lower level library than socket.io so the socket.io is built on engine.io. http://stackoverflow.com/questions/8542502/whats-the-difference-between-engine-io-and-socket-io – Footniko Sep 17 '15 at 14:49