当前位置: 首页 > news >正文

商城网站开发模板河北百度seo关键词

商城网站开发模板,河北百度seo关键词,网页制作图片上加文字,wordpress seo蜘蛛访问统计插件WebSocket 浏览器通过JavaScript向服务器发出建立WebSocket链接的请求,链接建立后,客户端和服务器端就可以通过TCP链接直接交互数据。WebSocket链接后可以通过send()方法来向服务器发送数据,并通过onnessage事件来接受服务器返回的数据。 创…

WebSocket

浏览器通过JavaScript向服务器发出建立WebSocket链接的请求,链接建立后,客户端和服务器端就可以通过TCP链接直接交互数据。WebSocket链接后可以通过send()方法来向服务器发送数据,并通过onnessage事件来接受服务器返回的数据。

创建WebSocket对象

let ws = new WebSocket(server);

WebSocket参考

WebSocket - Web API 接口参考 | MDN

代码

<template><el-row class="app-container"><el-button type="primary" @click="testSend">主要按钮</el-button></el-row>
</template><script>export default {name: 'Monitoring',data() {return {websocket: null, // WebSocket对象reconnectInterval: 3000, // 重连间隔时间(毫秒)restartWebsocket: null , // 重启定时器heartbeatInterval: null, // 心跳定时器};},created() {if (typeof WebSocket == "undefined") {console.log("您的浏览器不支持WebSocket");} else {this.setupWebSocket(); // 创建WebSocket连接}},methods: {testSend() { // 测试const send = {"keywords": "xxx",}this.sendMessage(JSON.stringify(send));},// websocket初始化setupWebSocket() {this.websocket = new WebSocket("ws://xxx"); // 创建WebSocket连接this.websocket.onopen = this.onWebSocketOpen; // WebSocket连接打开时的处理函数this.websocket.onmessage = this.onWebSocketMessage; // 收到WebSocket消息时的处理函数this.websocket.onclose = this.onWebSocketClose; // WebSocket连接关闭时的处理函数},closeWebSocket() { // 关闭if (this.websocket) {this.websocket.close(); // 关闭WebSocket连接}},// 开启 WebSocket;启动心跳检测onWebSocketOpen() {console.log("WebSocket connection is open");this.startHeartbeat();},// 处理从服务器接收的消息onWebSocketMessage(event) {if (event.data) {const message = JSON.parse(event.data);//    根据业务来处理数据console.log("Message from server ", message);}},// 关闭 WebSocket;停止心跳检测onWebSocketClose() {console.log("WebSocket connection is closed");this.stopHeartbeat(); // WebSocket连接关闭时,停止心跳检测this.restartWebsocket = setTimeout(this.setupWebSocket, this.reconnectInterval); // 在一定时间后重连WebSocket},// 向服务器发送消息sendMessage(message) {if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {this.websocket.send(message); // 发送消息到WebSocket服务器}},// 开启心跳检测startHeartbeat() {this.heartbeatInterval = setInterval(() => {if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {this.websocket.send(); // 发送心跳消息}}, 1000); // 每1秒发送一次心跳},// 停止心跳检测stopHeartbeat() {if (this.heartbeatInterval) {clearInterval(this.heartbeatInterval); // 停止心跳检测定时器}},// 停止重启检测stopRestartWebsocket() {if (this.restartWebsocket) {clearInterval(this.restartWebsocket); // 停止心跳检测定时器}},},beforeDestroy() {this.stopHeartbeat() // 停止心跳this.stopRestartWebsocket() // 停止重启this.closeWebSocket(); // 在组件销毁前关闭WebSocket连接},
}
</script><style scoped></style>

http://www.hkea.cn/news/742071/

相关文章:

  • 德化网站建设企业中层管理人员培训课程
  • 网站怎么通过流量赚钱爱站网能不能挖掘关键词
  • 网站建设课后感营销型网站有哪些平台
  • 哪个网站做生鲜配送厦门seo外包公司
  • 水电行业公司设计logo重庆seo排名扣费
  • 可信赖的南昌网站制作站长工具网站
  • 济南建站公司电话成都关键词自然排名
  • 门户网站开发公司推广网页
  • 如何做网站认证实时军事热点
  • 上海的网站建设公司哪家好企业网站建设
  • 专业b2c电商网站制作网站推广要点
  • 现在的网站用什么程序做百度云官网登录入口
  • vs做网站怎样加数据库新闻小学生摘抄
  • 广州做网站mxszpt小说排行榜
  • 有什么网站是python做的网站营销策划公司
  • 长春有什么好的网站制作公司链接购买
  • 毕设网站佛山网站建设十年乐云seo
  • 北京做网站建设的公司哪家好手机怎么创建网站
  • winforms做网站注册百度账号
  • 玉泉路网站建设营销培训课程有哪些
  • 渭南做网站费用搜索引擎排名优化是什么意思
  • 做网站开发需要学什么软件微信公众平台开发
  • 网站整体营销方案网络营销的特点是什么?
  • 国内知名的网站建设公司有哪些百度指数专业版app
  • 画画外包网站如何推广一个网站
  • 互联网公司响应式网站深圳google推广
  • 深圳网站设计哪好什么推广平台比较好
  • 打开英文网站字体不对教程seo推广排名网站
  • 昭通市建设局网站太原百度关键词优化
  • 个人建网站允许吗seo职位要求