简体   繁体   English

如何重新连接浏览器Websocket客户端?

[英]How to re-connect a browser websocket client?

I'm looking for a robust way to reconnect (infinitely retry) a WS client when the server goes down. 我正在寻找一种当服务器关闭时重新连接(无限重试)WS客户端的可靠方法。 I used different approaches, but if the server is down for too much time, the client must be manually refreshed (F5). 我使用了不同的方法,但是如果服务器停机时间过多,则必须手动刷新客户端(F5)。 Moreover the onClose event, sometimes is not fired. 而且onClose事件有时不触发。

Thank you. 谢谢。 LM LM

you can set an interval to check the websocket.readyStates value. 您可以设置一个间隔来检查websocket.readyStates值。 if the value is not equal 1, then you can call a function to reconnect the websocket. 如果该值不等于1,则可以调用一个函数以重新连接websocket。

I created a library which build websocket and its server easily. 我创建了一个库,可以轻松构建websocket及其服务器。 The useful features including re-connection if the websocket is closed. 有用的功能包括在websocket关闭时重新连接。

wsm - WebSocket Manager wsm-WebSocket管理器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM