大佬教程收集整理的这篇文章主要介绍了html5 – 如何捕获:WebSocket连接到’ws://失败:连接建立错误:net :: ERR_CONNECTION_REFUSED,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
WebSocket connection to 'ws://127.0.0.1:7777/api' Failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
init: function () { this.m_wsiSendBinary = new WebSocket("ws://127.0.0.1:7681/wsapi"); this.m_wsiSendBinary.onopen = function(evt) { cc.log("Send Binary WS was opened."); }; this.m_wsiSendBinary.onmessage = (function(evt) { this.handleServerResponse(yStr); this.m_wsiSendBinary.onerror = function(evt) { }; this.m_wsiSendBinary.onclose = function(evt) { cc.log("m_wsiSendBinary websocket instance closed."); self.m_wsiSendBinary = null; }; }).bind(this);
两项业务要求:
> BR1 – 当服务器不可用时处理初始化状态.
> BR2 – 服务器停止时的处理状态.
BR1的解决方案
var global_connection_openned=null;//Here you have the result init: function () { global_connection_openned=false; this.m_wsiSendBinary = new WebSocket("ws://127.0.0.1:7681/wsapi"); this.m_wsiSendBinary.onopen = function(evt) { global_connection_openned=true; };
BR2解决方案(假设为BR1)
//somewhere in your project called by seTinterval(..) which will detect the connection is lost (and tries to reestablish/reopen the connetion. { if (this.m_wsiSendBinary==null || this.m_wsiSendBinary.readyState==3) this.init(); if (!global_connection_openned) this.m_wsiSendBinary=null; }
无论如何,如果有这个用例的坚实和正确的解决方案,我真的很好奇.
以上是大佬教程为你收集整理的html5 – 如何捕获:WebSocket连接到’ws://失败:连接建立错误:net :: ERR_CONNECTION_REFUSED全部内容,希望文章能够帮你解决html5 – 如何捕获:WebSocket连接到’ws://失败:连接建立错误:net :: ERR_CONNECTION_REFUSED所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。