Friday, October 16, 2020

What is default timeout of WebSocket


pingTimeout 5000 how many ms without a pong packet to consider the connection closed

pingInterval 25000 how many ms before sending a new ping packet

upgradeTimeout 10000 how many ms before an uncompleted transport upgrade is cancelled


The pingTimeout and pingInterval parameters will impact the delay before a client knows the server is not available anymore. For example, if the underlying TCP connection is not closed properly due to a network issue, a client may have to wait up to pingTimeout + pingInterval ms before getting a disconnect event.


The order of the transports array is important. By default, a long-polling connection is established first, and then upgraded to WebSocket if possible. Using ['websocket'] means there will be no fallback if a WebSocket connection cannot be opened.


const server = require('http').createServer();


const io = require('socket.io')(server, {

  path: '/test',

  serveClient: false,

  // below are engine.IO options

  pingInterval: 10000,

  pingTimeout: 5000,

  cookie: false

});


server.listen(3000);




References:

https://socket.io/docs/server-api/#new-Server-httpServer-options


No comments:

Post a Comment