当前位置:网站首页>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)
}
边栏推荐
- Compatibility description between kingbasees and Oracle (2. Data type)
- 多传感器融合定位(三)——惯性技术
- 搭载新一代超安全蜂窝电池,思皓爱跑上市13.99万元起售
- Worthington -- Specification of Worthington trypsin inhibitor
- 深度剖析集成学习Xgboost
- Mongodb index add, view, export, delete
- Multi sensor fusion positioning (II) -- map based positioning
- [detailed and super simple] how to use websocket links
- Arm-A53资料「建议收藏」
- 2022t elevator repair examination questions and simulation examination
猜你喜欢

控件 圆角描边 MaterialShapeDrawable

实时数仓:美团基于Flink的实时数仓建设实施

脲酶丨Worthington杰克豆脲酶的特性及测定方案

SAP oracle 复制新实例后数据库远程连接报错 ora-01031

多传感器融合定位(三)——惯性技术

Uricase - Characteristics of uricase in Worthington pig liver:

PowerCL 批量创建及管理虚拟交换机

xss.haozi.me靶场详解

Pagoda phpMyAdmin unauthorized access vulnerability

智能垃圾桶(七)——SG90舵机的介绍与使用(树莓派pico实现)
随机推荐
实时数仓:网易严选基于Flink的实时数仓实践
hutool官网(hutool好用吗)
Asynchronism and synchronization of visa write and read functions by LabVIEW
Compatibility description between kingbasees and Oracle (4. SQL)
经典的拓扑排序问题——LeetCode207 课程表+LeetCode210 课程表II
Arm-a53 data "recommended collection"
Manufacturing steps of interactive slide screen in exhibition hall
AUTOCAD——Excel表格导入CAD、CAD合并两兄弟
SAP 临时表空间错误处理
苹果官网正在更新维护 Apple Store,国行 iPhone 13 / Pro 等产品将最高优惠 600 元
Worthington核糖核酸测定详细攻略
搭载新一代超安全蜂窝电池,思皓爱跑上市13.99万元起售
深度剖析集成学习Xgboost(续)
Okaleido生态核心权益OKA,尽在聚变Mining模式
Tyrosine decarboxylase -- characteristics of tyrosine decarboxylase of Streptococcus faecalis in Worthington
Machine learning problem notes
[data mining engineer - written examination] Dahua shares in 2022
Use pytoch to quickly train the network model
多传感器融合定位(三)——惯性技术
Codeforces Round #474 (Div. 1 + Div. 2) - C, F