当前位置:网站首页>【详细超简单】如何使用WebSocket链接
【详细超简单】如何使用WebSocket链接
2022-07-28 21:56:00 【沐卿゚】
created:
this.contactSocket()
methods
contactSocket(){
let webSocket = null;
let socketOpen = false;
let that=this
if ("WebSocket" in window) {
webSocket = new WebSocket("ws://后台给的url");
webSocket.onopen = function (){
console.log("连接成功!");
webSocket.send(that.token)
socketOpen = true
};
webSocket.onmessage = function (evt) {
var received_msg = evt.data;
console.log("接受消息:" + received_msg);
};
webSocket.onclose = function () {
console.log("连接关闭!");
that.reconnect()
};
webSocket.onerror = function () {
console.log("连接异常!");
};
}
},
// 重连
reconnect(){
console.log('重新连接')
setInterval(this.contactSocket(), 10000)
},
直接换好链接调用就行了,非常简单
边栏推荐
- 金仓数据库 KingbaseES与Oracle的兼容性说明(2. 数据类型)
- [self] - question brushing - dynamic programming
- Neglected smart TV applet field
- [self] - brush questions BFS
- 经典双栈实现队列,注意遍历栈的判定条件修改。
- 【自】-刷题-动态规划
- Pin mapping relationship of stm32f103c series single chip microcomputer under Arduino framework
- 使用这个,你发的消息就无法被监控了
- Codeforces Round #474 (Div. 1 + Div. 2) - C, F
- MySQL functions
猜你喜欢
宝塔 phpmyadmin未授权访问漏洞
【自】-刷题-逻辑
互动滑轨屏在展厅中应用的制作步骤
2022年R2移动式压力容器充装考题模拟考试平台操作
Class, leetcode919 -- complete binary tree inserter
【自】-刷题-数组
电脑不知卸载什么,打不开计算器无法编辑截图功能打不开txt文件等等解决方案之一
利用递归和链表头插法实现链表成组的翻转——LeetCode25 K个一组翻转链表
My second uncle is angry and swipes the screen all over the network. How can he cure my spiritual internal friction?
field injection is not recommended 的解决办法
随机推荐
[self] - brush questions BFS
Pin mapping relationship of stm32f103c series single chip microcomputer under Arduino framework
深度之眼(十八)——偏导数
【自】-刷题-动态规划
利用递归和链表头插法实现链表成组的翻转——LeetCode25 K个一组翻转链表
毕业三年之际写给可能迷茫的你我[转]
深度剖析集成学习Xgboost(续)
Rhce第一天
22牛客多校day1 I - Chiitoitsu 概论dp
添加构建依赖项报错
General paging - front desk
Development of small programs ②
XML modeling
Optimization and implementation of custom MVC
2022年R2移动式压力容器充装考题模拟考试平台操作
网络流量监控工具iftop
The classic dual stack implementation queue, pay attention to the modification of the judgment conditions of traversing the stack.
CV目标检测模型小抄(2)
Use of typescript class
Fundamental inquiry binary tree