当前位置:网站首页>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)
}
边栏推荐
- 添加构建依赖项报错
- My second uncle is angry and swipes the screen all over the network. How can he cure my spiritual internal friction?
- 使用Pytorch快速训练网络模型
- How powerful can top "hackers" be? Internet access without signal, expert: high-end operation!
- 深度剖析集成学习Xgboost(续)
- 剑指 Offer 64. 求1+2+…+n,逻辑运算符短路效应
- 连接池-归还连接详解(下)
- 阻塞式队列
- EN 12101-8:2011烟雾和热量控制系统防烟挡板—CE认证
- Codeforces Round #810 (Div. 2) A - C
猜你喜欢

超参数优化(网格搜索和贝叶斯优化)
![[self] - brush questions set](/img/de/46582086addbe5465d658081516f4c.png)
[self] - brush questions set

Manufacturing steps of interactive slide screen in exhibition hall

Apple's official website is being updated to maintain the apple store. Products such as the iPhone 13 / pro of the Bank of China will enjoy a maximum discount of 600 yuan

Equipped with a new generation of ultra safe cellular batteries, Sihao aipao is available from 139900 yuan

尿酸酶丨Worthington猪肝尿酸酶的特征:

电商数据模型设计

YOLOV5学习笔记(一)——原理概述

浪潮ClusterEngineV4.0 远程命令执行漏洞 CVE-2020-21224

Worthington核糖核酸酶B历史和化学性质说明
随机推荐
Kingbasees client programming interface guide ODBC (4. Create data source)
Deep analysis of integrated learning xgboost
阻塞式队列
OpenCV宏定义
SQL left connection, internal connection writing method "recommended collection"
NPDP考试需要携带什么?文具携带说明
Inspur clusterenginev4.0 remote command execution vulnerability cve-2020-21224
Tyrosine decarboxylase -- characteristics of tyrosine decarboxylase of Streptococcus faecalis in Worthington
PowerCLi VMware vCenter 通过自建的PXE Server一键批量部署常规New-VM
Okaleido生态核心权益OKA,尽在聚变Mining模式
VirtualLab基础实验教程-8.傅里叶变换(1)
深度之眼(十八)——偏导数
Codeforces Round #810 (Div. 2) A - C
剑指 Offer 55 - I. 二叉树的深度
尿酸酶丨Worthington猪肝尿酸酶的特征:
AUTOCAD——Excel表格导入CAD、CAD合并两兄弟
Xss.haozi.me range details
Codeforces Round #810 (Div. 2) A - C
PowerCL 批量创建及管理虚拟交换机
Arm-A53资料「建议收藏」