Socket.io specifying heartbeat

后端 未结 2 683
清酒与你
清酒与你 2020-12-30 05:11

I can\'t seem to find out how to set the heartbeat options for socket.io? I\'d love to be able to specify what happens when a \"timemout\" happens, and when the server hasn\

2条回答
  •  粉色の甜心
    2020-12-30 05:31

    Socket.IO uses engine.io, which allows you to specify ping interval and ping timeout, like so:

    var app = require('express')();
    var http = require('http').Server(app);
    
    var io = require('socket.io')(http, {'pingInterval': 2000, 'pingTimeout': 5000});
    

    (2 second interval and 5 second timeout is just an example. It might be to frequent for your use case)

提交回复
热议问题