美文网首页
websocket心跳函数

websocket心跳函数

作者: Feng_Du | 来源:发表于2021-12-24 14:02 被阅读0次

调用
new WebSocket(url).onmessage=()=>{
heartbeat.reset();
}

//心跳
const heartbeat = new function () {
this.timeout = 18000;
this.timeoutObj = null;
this.reset = function () {
clearTimeout(this.timeoutObj);
this.start();
}
this.start = function () {
this.timeoutObj = setTimeout(function () {
ws.send("heartbeat");
this.reset()
}.bind(this), this.timeout);
}
}

相关文章

网友评论

      本文标题:websocket心跳函数

      本文链接:https://www.haomeiwen.com/subject/ldvlqrtx.html