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

西安网站seo技术厂家产品推广软文200字

西安网站seo技术厂家,产品推广软文200字,哈尔滨网站制作公司有哪些,开网站要多少钱如题 心跳:4秒发一次 断线:2秒后自动重连 收发:发送和返回json,处理粘包断包等情况,json字符串最大长度9999 缓存:未连接时,自动缓存100个包,当连接时会自动发出 JS代码 var MyWeb…

如题
心跳:4秒发一次
断线:2秒后自动重连
收发:发送和返回json,处理粘包断包等情况,json字符串最大长度9999
缓存:未连接时,自动缓存100个包,当连接时会自动发出

JS代码

var MyWebSocket = {ws : null,isConnected : false,strLast : "",isDebug : true,url : "",//msreconnectTimeout : 2000,sendBuffMaxSize : 100,arrSendBuff : [],timer : 0,connect : function(url){this.url = url;var that = this;if( this.ws != null ){this.ws.onopen = null;this.ws.onmessage = null;this.ws.onclose = null;this.ws.onerror = null;}if( this.timer==0 ){timer = setInterval( this.heart, 4000, this );}this.ws = new WebSocket(url);this.ws.onopen = function(){that.isConnected = true;//当WebSocket创建成功时,触发onopen事件that.log("open");that.ws.send("0002{}"); //将消息发送到服务端that.sendBuffJson();}this.ws.onmessage = function(e){that.log(e.data);that.strLast += e.data;var strlen = that.strLast.length;if( strlen > 4 ){var len = parseInt( "0x" + that.strLast.substr(0, 4));if( len+4 <= strlen ){var s = that.strLast.substr(4, len+4);that.strLast = that.strLast.substr(len+4);that.log("msg come");that.log(s);if( that.onMsgCome != null ){this.onMsgCome(JSON.parse(s));}}}}this.ws.onclose = function(e){//当客户端收到服务端发送的关闭连接请求时,触发onclose事件that.log("close");that.isConnected = false;that.reconnect();}this.ws.onerror = function(e){//如果出现连接、处理、接收、发送数据失败的时候触发onerror事件that.log(error);}},reconnect : function(){if( this.reconnectTimeout > 0 ){setTimeout(this.doReconnect, this.reconnectTimeout, this);}else this.doReconnect(this);},doReconnect : function(that){that.connect(that.url);},sendBuffJson : function(){var len = this.arrSendBuff.length;for( var i=0; i<len; i++ ){var json = this.arrSendBuff[i];this.send(json);}return len;},heart : function(that){if( !that.isConnected ) return;that.timerNum++;if( that.timerNum > that.sendNum ){that.log("heart");that.ws.send("0000");}},timerNum : 1,sendNum : 1,send : function(json){if( !this.isConnected ){if( this.arrSendBuff.length < this.sendBuffMaxSize ){this.arrSendBuff.push(json);}return;}this.sendNum = this.timerNum + 1;var s = JSON.stringify(json);var prev = "0000" + s.length.toString(16);prev = prev.substr(prev.length-4);s = prev + s;this.ws.send(s);},log : function(s){if( this.isDebug ) console.log(s);},//信息回调回调函数onMsgCome : null,
}

测试代码

<!DOCTYPE html>
<html>
<head><meta charset=utf-8 /><title>MyWebSocket</title>
</head>
<script type="text/javascript"> </script>
<body><script src="MyWebSocket.js"></script><script>var mw = Object.create(MyWebSocket);mw.connect("ws://127.0.0.1:8888");mw.onMsgCome = function(json){console.log(json);}setInterval(xx, 3000);function xx(){var json = {};json.url = "xx";json.data = {};mw.send(json);}</script></body></html>
http://www.hengruixuexiao.com/news/32759.html

相关文章:

  • 在线做视频网站网站流量统计系统
  • web前端学习路线seo点击软件哪个好用
  • 2015百度竞价单页面网站模板源码设计百度seo排名优化公司哪家强
  • 网站中查看熊掌号怎么做的哪有免费的网站
  • 用网站开发客户发邮件网络推广是以企业产品或服务
  • wordpress模版做网站广州疫情最新新增
  • 网站的分类有哪些天津债务优化公司
  • 网站打开速度规定多长时间上海专业seo公司
  • 番禺区网站建设哪里有google永久免费的服务器
  • 腾龙时时彩做号软件官方网站找竞价托管公司
  • b2c的交易平台有哪些厦门seo推广优化
  • 昆明网站建设哪家便宜网站建设方案优化
  • 百度站长平台诊断网站优化公司哪个好
  • 赤峰网站开发公司常州seo关键词排名
  • 太原网站公司seo能干一辈子吗
  • 网站制作公司制作网站seo确定关键词
  • 建设通是正规网站吗数据分析师培训机构推荐
  • 信科网络广州建网站网站统计
  • 多元 集团 网站建设方案网络营销的内涵
  • 外贸鞋的网站建设海南网站设计
  • 重庆市建设工程质量协会网站竞价推广托管开户
  • 政府网站建设愿景百度引擎搜索
  • 做寝室介绍网站如何做推广宣传
  • 设计免费素材网站服务器ip域名解析
  • 微信网站什么做的小红书推广怎么收费
  • wordpress加快php渲染福州网seo
  • 威海网站开发制作推广方案怎么写
  • 饭店网站建设策划方案如何建立网站平台的步骤
  • 制作免费制作个人网站怎么做百度快照排名
  • 企业网站不备案可以吗爱站长尾词