断开连接后Socket.connect不起作用

时间:2019-08-25 00:24:59

标签: javascript sockets websocket socket.io

我尝试在断开连接后重新连接。但是,我能够看到“尝试重新连接<> <> <> <> <> <> <> <> <>”打印,但是套接字永远无法重新连接。为什么?

    socket.on('connect', () => {
      console.log('socket connected ====================');
      reconnectTimer && clearInterval(reconnectTimer);
      dispatch(updateConnectingStatus(false));
      dispatch(updateSocketStatus(true));
    });

    socket.on('disconnect', reason => {
      console.log('socket disconnect *******************');
      dispatch(updateConnectingStatus(false));
      dispatch(updateSocketStatus(false));

      // reconnect.
      reconnectTimer = setInterval(() => {
        console.log('try reconnect <><><><><><><><>');
        socket.connect();
      }, 1500);
    });```

0 个答案:

没有答案