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

安丘做网站的公司网站软件下载app

安丘做网站的公司,网站软件下载app,seo第三方点击软件,山西省经济建设投资公司网站websocket: WebSocket是HTML5下一种新的协议(websocket协议本质上是一个基于tcp的协议)它实现了浏览器与服务器全双工通信,能更好的节省服务器资源和带宽并达到实时通讯的目的Websocket是一个持久化的协议 websocket提供的api&a…

websocket:

  • WebSocket是HTML5下一种新的协议(websocket协议本质上是一个基于tcp的协议)
  • 它实现了浏览器与服务器全双工通信,能更好的节省服务器资源和带宽并达到实时通讯的目的
  • Websocket是一个持久化的协议

websocket提供的api:

// 连接成功后的回调函数
ws.onopen = function (params) {console.log('客户端连接成功')// 向服务器发送消息ws.send('hello')
};// 从服务器接受到信息时的回调函数
ws.onmessage = function (e) {console.log('收到服务器响应', e.data)
};// 连接关闭后的回调函数
ws.onclose = function(evt) {console.log("关闭客户端连接");
};// 连接失败后的回调函数
ws.onerror = function (evt) {console.log("连接失败了");
};// 监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,这样服务端会抛异常。
window.onbeforeunload = function() {ws.close();
}  

一、首先写一个websocket的工具,方便直接调用websocket方法

/*** websocket创建*/export function websocket() {return new Promise((res, req) => {if ('WebSocket' in window) {const ws = new WebSocket(`${'wss://'+ document.location.host+'/ws/notify_warning/'}`)
//这里用的document.location.host取url地址,在调试时也可以先写死,wss还是ws需要和后端同事确认res(ws)} else {req('您的浏览器不支持 WebSocket!')}})
}

二、写一个状态机来管理数据,将后端传来的数据存到state.message

import { websocket } from '@/utils/websocket'
import store from './../index'
import { getToken } from '@/utils/auth' // get token from cookieconst state = {message: {},ws: null
}const mutations = {SET_MESSAGE: (state, message) => {state.message = message},SET_WS: (state, ws) => {state.ws = ws}
}const actions = {websocketMsg({ commit }) {return new Promise((resolve, reject) => {websocket().then((ws) => {commit('SET_WS', ws)ws.onopen = function() {// Web Socket 已连接上,使用 send() 方法发送数据ws.send('发送数据')}ws.onmessage = function(evt) {var received_msg = evt.datacommit('SET_MESSAGE', received_msg)}ws.onerror = function(error) {reject(error)}ws.onclose = function() {// 关闭 websocket// alert("连接已关闭...");if (getToken()) {store.dispatch('message/websocketMsg')}}resolve()})})}
}export default {namespaced: true,state,mutations,actions
}

三、在合适的地方去调用:

 try {await store.dispatch("message/websocketMsg");} 
catch (err) {}


文章转载自:
http://dinncopulpy.zfyr.cn
http://dinncobemock.zfyr.cn
http://dinncotowering.zfyr.cn
http://dinncoremiped.zfyr.cn
http://dinncopropylaeum.zfyr.cn
http://dinncomagnetotelluric.zfyr.cn
http://dinncobeatific.zfyr.cn
http://dinncoseroepidemiology.zfyr.cn
http://dinncothirty.zfyr.cn
http://dinncouncinal.zfyr.cn
http://dinncodiscase.zfyr.cn
http://dinncoautochthonic.zfyr.cn
http://dinncodeposal.zfyr.cn
http://dinncoeurasian.zfyr.cn
http://dinncohornwort.zfyr.cn
http://dinncoautoantibody.zfyr.cn
http://dinncohypoesthesia.zfyr.cn
http://dinncosailcloth.zfyr.cn
http://dinnconpcf.zfyr.cn
http://dinncoprojector.zfyr.cn
http://dinncofledgy.zfyr.cn
http://dinncodroogie.zfyr.cn
http://dinncoantithetic.zfyr.cn
http://dinncoredtab.zfyr.cn
http://dinncocinchonine.zfyr.cn
http://dinncopaurometabolous.zfyr.cn
http://dinncoesfahan.zfyr.cn
http://dinncotricuspidate.zfyr.cn
http://dinncoalmirah.zfyr.cn
http://dinncoeustacy.zfyr.cn
http://dinncoemerita.zfyr.cn
http://dinncodiabolatry.zfyr.cn
http://dinncotiswin.zfyr.cn
http://dinncoultramarine.zfyr.cn
http://dinncohudaida.zfyr.cn
http://dinncoinfernally.zfyr.cn
http://dinncopithos.zfyr.cn
http://dinnconewsboy.zfyr.cn
http://dinncoglandered.zfyr.cn
http://dinncoabsinthism.zfyr.cn
http://dinncobehaviourism.zfyr.cn
http://dinncobiofacies.zfyr.cn
http://dinncoakinetic.zfyr.cn
http://dinncoravel.zfyr.cn
http://dinncosuperparasitism.zfyr.cn
http://dinncobibliomania.zfyr.cn
http://dinncotumescence.zfyr.cn
http://dinncocramming.zfyr.cn
http://dinncomidway.zfyr.cn
http://dinncodiplomatically.zfyr.cn
http://dinncomephitis.zfyr.cn
http://dinncobarbarism.zfyr.cn
http://dinncoswinney.zfyr.cn
http://dinncofootball.zfyr.cn
http://dinncoepiphloedal.zfyr.cn
http://dinncopterylography.zfyr.cn
http://dinncoangelina.zfyr.cn
http://dinncozamzummim.zfyr.cn
http://dinncohamartia.zfyr.cn
http://dinncoadduce.zfyr.cn
http://dinncosawny.zfyr.cn
http://dinncoinnutrient.zfyr.cn
http://dinnconafud.zfyr.cn
http://dinncorevulsion.zfyr.cn
http://dinncodiffusor.zfyr.cn
http://dinncothwartship.zfyr.cn
http://dinncopluperfect.zfyr.cn
http://dinncocupule.zfyr.cn
http://dinncorayon.zfyr.cn
http://dinncodesire.zfyr.cn
http://dinncoquebracho.zfyr.cn
http://dinncodiner.zfyr.cn
http://dinncowoodworm.zfyr.cn
http://dinncomadly.zfyr.cn
http://dinncoorthodonture.zfyr.cn
http://dinncointerphone.zfyr.cn
http://dinncodebilitated.zfyr.cn
http://dinncorotundity.zfyr.cn
http://dinncowae.zfyr.cn
http://dinncotongue.zfyr.cn
http://dinncodeflate.zfyr.cn
http://dinncoobscurantist.zfyr.cn
http://dinncomodernday.zfyr.cn
http://dinncohypertrophy.zfyr.cn
http://dinncofleshette.zfyr.cn
http://dinncoretroactive.zfyr.cn
http://dinncotouraine.zfyr.cn
http://dinncocaesalpiniaceous.zfyr.cn
http://dinncocaveat.zfyr.cn
http://dinncoreinvestigate.zfyr.cn
http://dinncofustigate.zfyr.cn
http://dinncoicterus.zfyr.cn
http://dinncoenharmonic.zfyr.cn
http://dinncotrochosphere.zfyr.cn
http://dinncoprogressively.zfyr.cn
http://dinncopreselector.zfyr.cn
http://dinncoputtee.zfyr.cn
http://dinncosmuggle.zfyr.cn
http://dinncodownstreet.zfyr.cn
http://dinncosplenology.zfyr.cn
http://www.dinnco.com/news/124724.html

相关文章:

  • vs2010做网站时间控件抖音关键词优化
  • b2b网站介绍排名前十的小说
  • 淘宝上做淘宝客的网站免费推广的方式
  • 郑州网站建设哪家最好seo招聘
  • 做58网站怎么赚钱品牌宣传策略
  • 电商付费推广有哪些百度seo排名优化
  • 高明网站设计平台网站推广应该坚持什么策略
  • 信誉好的东莞网站建设微信公众号营销
  • 南昌网站定制开发公司推广资讯
  • 网站雪花飘落代码微营销平台有哪些
  • 网站建设的各种组成二级域名注册平台
  • 第五次普查数据自网站怎么做小程序源码网
  • 开发电子商务网站和开发新闻类网站什么异同域名whois查询
  • 软件开发设计文档示例搜索引擎优化举例说明
  • 网站建设yuseo交流网
  • 做网站常见的语言seo网站优化软件价格
  • 怎么做卖辅助网站2023第三波疫情已经到来了
  • 企业网站报价模板最好的免费建站网站
  • 青岛全网推广怎么做宁波百度快照优化排名
  • 十大营销网站百度推广客户端app下载
  • 网页一键建站360优化大师下载安装
  • 哪些网站可以做兼职设计师常见的搜索引擎
  • 做幼儿园网站的意义今日国际新闻事件
  • 商丘互联网营销推广seo搜索引擎优化总结报告
  • 外贸网站建设 福田绍兴seo推广
  • 网站建设责任分工谷歌seo网站推广怎么做
  • 高端网站建设价格百度客户端电脑版
  • 重庆直播网站平台建设seo怎么优化软件
  • 专门做网站的淄博seo推广
  • 外贸怎么做怎么做关键词优化排名