简体   繁体   中英

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. I used different approaches, but if the server is down for too much time, the client must be manually refreshed (F5). Moreover the onClose event, sometimes is not fired.

Thank you. LM

you can set an interval to check the websocket.readyStates value. if the value is not equal 1, then you can call a function to reconnect the websocket.

I created a library which build websocket and its server easily. The useful features including re-connection if the websocket is closed.

wsm - WebSocket Manager

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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