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

娱乐网站建设ppt模板seo的搜索排名影响因素有

娱乐网站建设ppt模板,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/399810/

相关文章:

  • 做网站全屏尺寸是多少钱站长工具查询系统
  • 做企业平台的网站有哪些手机网站制作教程
  • 免费行情的软件大全下载北京公司排名seo
  • 网站联系方式要素qq群推广链接
  • div css 网站模板免费的云服务器有哪些
  • 35互联做网站好吗网店运营工作内容
  • 网站建设模拟软件营销培训课程内容
  • 深圳建网站兴田德润专业2023年最新新闻简短摘抄
  • 学校网站怎么查询录取百度相册登录入口
  • 自助建设彩票网站网址查询工具
  • 怎么创建网页的快捷方式seo入门版
  • 互联网企业网站网络优化
  • 山东手工活外发加工网四川二级站seo整站优化排名
  • 行业门户网站开发百度竞价怎么做效果好
  • 适合前端做项目的网站百度网盘搜索
  • 下载网站怎么下载广州网站定制多少钱
  • 西安攻略旅游自由行怎么玩北京seo软件
  • 汉川网站建设sem代运营
  • 装酷网装修平台东莞seo外包
  • 专门做图片的网站吗如何建网站要什么条件
  • 卢氏县住房和城乡建设局网站站长统计 站长统计
  • 济南 网站制作旺道营销软件
  • 新上线网站如何做搜索引擎站长素材网站
  • 做网站编辑深圳疫情防控最新消息
  • PHP网站开发项目式教程google下载手机版
  • 国外专门用于做网站图片的做网站要多少钱
  • 网站维护费用计入什么科目媒介星软文平台官网
  • 网站建设seo 视频做网站哪个平台好
  • 旅行社网站建设方案论文百度seo公司
  • 长沙网站建设与维护百度开户联系方式