当前位置:网站首页>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)
}
边栏推荐
- 超参数优化(网格搜索和贝叶斯优化)
- [self] - question brushing - peak value
- 多传感器融合定位(二)——基于地图的定位
- Codeforces Round #810 (Div. 2) A - C
- 猿人学第二十题
- hutool官网(hutool好用吗)
- Hutool official website (is hutool easy to use)
- C language n*n matrix evaluation and inverse matrix [easy to understand]
- Is the declarative code of compose so concise?
- Kingbasees client programming interface guide ODBC (4. Create data source)
猜你喜欢

Xss.haozi.me range details

field injection is not recommended 的解决办法

Exchange 2013 SSL证书安装文档

Inspur clusterenginev4.0 remote command execution vulnerability cve-2020-21224

What is a driver signature and how does the driver get a digital signature?

2022 simulated examination platform operation of hoisting machinery command examination questions

阻塞式队列

Multisensor fusion positioning (III) -- inertial technology

Class, leetcode919 -- complete binary tree inserter

深度剖析集成学习Xgboost
随机推荐
数据中台的那些“经验与陷阱”
What is a driver signature and how does the driver get a digital signature?
深度剖析集成学习GBDT
简述分组密码的加密分组链接模式的工作原理及其特点(密码学移位密码加密解密)
Mongodb index add, view, export, delete
E-commerce data model design
Uricase - Characteristics of uricase in Worthington pig liver:
hutool官网(hutool好用吗)
浪潮ClusterEngineV4.0 远程命令执行漏洞 CVE-2020-21224
Arm-a53 data "recommended collection"
Worthington核糖核酸酶B历史和化学性质说明
(22) two permutation (DP), package delivery (greedy)
npm更换最新淘宝镜像
2022 G2 power plant boiler stoker examination question bank simulated examination platform operation
VMware VCSA 7.0 Install
Arm-A53资料「建议收藏」
Learn browser decoding from XSS payload
宝塔 phpmyadmin未授权访问漏洞
Jincang database kingbasees client Programming Interface Guide - ODBC feature support constraints
编译原理研究性学习专题 2——递归下降语法分析设计原理与实现