当前位置:网站首页>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)
}
边栏推荐
- 2022 G2 power plant boiler stoker examination question bank simulated examination platform operation
- SAP oracle 复制新实例后数据库远程连接报错 ora-01031
- AUTOCAD——Excel表格导入CAD、CAD合并两兄弟
- OpenCV宏定义
- 你学过的每样东西,都会在你一生中的某个时刻派上用场(转)
- 深度剖析集成学习GBDT
- sql 左连接,内连接 的写法「建议收藏」
- Worthington -- Specification of Worthington trypsin inhibitor
- 【详细超简单】如何使用WebSocket链接
- Multi sensor fusion positioning (II) -- map based positioning
猜你喜欢

解决线程安全问题&&单例模式

pycharm新建项目

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

Wildcard ssl/tls certificate

机器学习问题笔记

Solve thread safety problems & singleton mode

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

电脑不知卸载什么,打不开计算器无法编辑截图功能打不开txt文件等等解决方案之一

Codeforces Round #810 (Div. 2) A - C

Manufacturing steps of interactive slide screen in exhibition hall
随机推荐
Hutool official website (is hutool easy to use)
有效供应链管理的八大绩效分析指标(上)
Pycharm new project
猿人学第二十题
实时数仓:网易严选基于Flink的实时数仓实践
YOLOV5学习笔记(一)——原理概述
Multisensor fusion positioning (III) -- inertial technology
深度之眼(十八)——偏导数
[self] - brush questions BFS
新一代超安全蜂窝电池 思皓爱跑上市13.99万元起售
Zibo station construction guide (aigler)
Best practices for migration of kingbasees v8.3 to v8.6 of Jincang database (3. Kingbasees migration capability support system)
Inspur clusterenginev4.0 remote command execution vulnerability cve-2020-21224
Explanation of history and chemical properties of Worthington ribonuclease B
迅为IMX6开发板QT系统创建AP热点基于RTL8723-交叉编译iptables
Multi sensor fusion positioning (II) -- map based positioning
类中多函数填写,LeetCode919——完全二叉树插入器
PowerCLi 批量添加esxi到vCenter
深度剖析集成学习Adaboost
尿酸酶丨Worthington猪肝尿酸酶的特征: