Stop socket.io from reconnecting

后端 未结 6 720
情歌与酒
情歌与酒 2020-12-31 05:58

Simple scenario:

  1. Client connects to server with socket.io (socket = io.connect(...))
  2. Server crashes
  3. Client tries to reconnect
6条回答
  •  执念已碎
    2020-12-31 06:34

    You might want to handle the reconnection yourself.

    // Disables the automatic reconnection
    var socket = io.connect('http://server.com', {
        reconnection: false
    });
    
    // Reconnects on disconnection
    socket.on('disconnect', function(){
        socket.connect(callback);
    });
    

    Note: old versions used reconnect instead of reconnection.

提交回复
热议问题