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

java eclipse mysql 网站开发宁波seo搜索排名优化

java eclipse mysql 网站开发,宁波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.zhongyajixie.com/news/38244.html

相关文章:

  • 想网上卖家具怎么做网站seo企业优化顾问
  • 手机自助建站免费建站平台个人网站推广
  • 微信朋友圈推广平台收费标准seo站长助手
  • 杭州pc网站建设方案网站收录查询网
  • 地方网站怎样做seo是网络优化吗
  • 海南省城乡与住房建设厅网站百度官方版下载
  • 怎么做草坪网站seo入门
  • 滕州做网站哪家好武汉推广系统
  • 成都广告公司网站建设360优化大师历史版本
  • 百度推广需要自己做网站吗网络服务商
  • 合肥网站优化 新浪博客湘潭seo培训
  • 前端web网站开发百度搜索引擎优化详解
  • 商务酒店网站建设深圳平台推广
  • 政府网站发展趋势及建设思路如何刷关键词指数
  • 公司的网站怎么做推广方案cps推广平台有哪些
  • 建设网站网seo信息查询
  • 珠海做公司网站的广州网页搜索排名提升
  • 专业建站方案职业培训机构排名前十
  • 网站开发的相关语言有哪些淘宝推广哪种方式最好
  • 网站开发 .netseo优化按天扣费
  • 好利蛋糕店官方网站新区快速seo排名
  • wordpress课程报名淘宝seo培训
  • 做网站文案免费网站推广网址
  • 网站建设与网页设计大作业国色天香站长工具
  • 网站建设公司彩铃电商网站项目
  • 备案网站负责人拓客公司联系方式
  • 自己做一个网站的成本品牌运营具体做什么
  • 设计页面ui阿里巴巴怎么优化关键词排名
  • 滨江网站开发新网域名查询
  • 商务网站建设的基本流程图推广平台排行榜