Socket.io specifying heartbeat

后端 未结 2 557
清酒与你
清酒与你 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)

    0 讨论(0)
  • 2020-12-30 05:51

    For me the following worked:

    var app = express(); 
    var server = require('http').createServer(app); 
    var io = require('socket.io')(server); 
    
    io.set('heartbeat timeout', 4000); 
    io.set('heartbeat interval', 2000);
    

    For package dependency versions:

    "express": "^4.12.3",
    "socket.io": "1.0"
    
    0 讨论(0)
提交回复
热议问题