当前位置:网站首页>Websocket heartbeat mechanism (keep alive mechanism)
Websocket heartbeat mechanism (keep alive mechanism)
2022-07-28 23:54:00 【Fairy loves fish】
principle : send ⽤setInterval and setTimeout Realization , every other ⼀ Send to the server after a period of time ⼀ A packet , Tell the server ⾃⼰ Still alive , If the server also
Live and return ⼀ A packet , If you disconnect , Client reconnection is required
1.Websocket Create when the connection is successful ⼼ Skip detection
socket.open() {
heart()
}
2.Websocket After receiving the message ⾏⼼ Skip reset
heart()
3. send ⽤setInterVal and setTimeout⽅ To achieve ⼼ jump
data() {
return {
timeoutObj: null,
serverTimeoutObj: null
}
}
heart() {
// 1. By turning off the timer and counting down ⾏ Reset ⼼ jump
clearInterVal(timeoutObj)
clearTimeout(serverTimeoutObj)
// 2. every other 30 Seconds to the server ⼀ A packet
this.timeoutObj = setInterVal(() => {
console.log(‘ Reset detection ⼼ jump ’)
const data = {}
socket.send(data) // Send packet
// 2 Seconds later The server closes the connection and reconnects without returning a packet
serverTimeoutObj = setTimeout(() => {
console.log(‘⼼ No jump , The connection is broken ’)
socket.close()
}, 2000)
}, 3000)
}
边栏推荐
- In depth analysis of integrated learning xgboost (Continued)
- SAP 临时表空间错误处理
- 毕业三年之际写给可能迷茫的你我[转]
- 使用Pytorch快速训练网络模型
- 2022 welder (Junior) work license questions and answers
- GhostNets on Heterogeneous Devices via Cheap Operations
- Class, leetcode919 -- complete binary tree inserter
- Multi sensor fusion positioning (II) -- map based positioning
- 深度剖析集成学习Adaboost
- 2022 simulated examination platform operation of hoisting machinery command examination questions
猜你喜欢

Zero view h5s video platform getUserInfo information disclosure vulnerability cnvd-2020-67113

深度之眼(十八)——偏导数

Pagoda phpMyAdmin unauthorized access vulnerability

Jincang database kingbasees client programming interface guide ODBC (2. Overview)

多传感器融合定位(二)——基于地图的定位

2022 simulated examination platform operation of hoisting machinery command examination questions

Genomic DNA isolation Worthington ribonuclease A

使用Pytorch快速训练网络模型

Wildcard ssl/tls certificate

什么是驱动程序签名,驱动程序如何获取数字签名?
随机推荐
Ape anthropology topic 20
xss.haozi.me靶场详解
苹果官网正在更新维护 Apple Store,国行 iPhone 13 / Pro 等产品将最高优惠 600 元
基因组 DNA 分离丨Worthington核糖核酸酶A
超参数优化(网格搜索和贝叶斯优化)
Hyperparametric optimization (grid search and Bayesian Optimization)
The classic dual stack implementation queue, pay attention to the modification of the judgment conditions of traversing the stack.
电脑不知卸载什么,打不开计算器无法编辑截图功能打不开txt文件等等解决方案之一
编译原理研究性学习专题 2——递归下降语法分析设计原理与实现
Worthington核糖核酸酶B历史和化学性质说明
【CNN】为什么CNN的卷积核大小一般都是奇数
使用Pytorch快速训练网络模型
Hutool official website (is hutool easy to use)
2022 welder (Junior) work license questions and answers
Worthington核糖核酸测定详细攻略
新一代超安全蜂窝电池 思皓爱跑上市13.99万元起售
2022 R2 mobile pressure vessel filling test question simulation test platform operation
双重for循环优化
Worthington -- Specification of Worthington trypsin inhibitor
Classic topological sorting problem -- leetcode207 curriculum +leetcode210 curriculum II