NodeJS Websocket how to reconnect when server restarts

后端 未结 4 2073
轮回少年
轮回少年 2020-12-09 10:15

In Node.js I\'m using websockets/ws for a WebSocket connection. Below is the code for the client. Let\'s say the server socket we are connecting to goes down for a minute. T

4条回答
  •  悲&欢浪女
    2020-12-09 10:44

    I've used https://github.com/joewalnes/reconnecting-websocket/blob/master/reconnecting-websocket.js with success.

    You should be able to do:

    ws = new ReconnectingWebSocket('ws://....');
    ws.reconnectInterval = 60000; // try to reconnect after 10 seconds
    

提交回复
热议问题