2

我一直在网上搜索我在 3g/4g 网络上使用 socketio 客户端时遇到的问题。它似乎连接,但并没有长时间保持连接,它保持连接大约 60 秒然后断开连接,当重新连接尝试事件触发时再次连接,但重复上述行为。

有谁知道为什么会发生这种情况或如何解决?

提前致谢!

下面是我用来启动 de socket 的代码示例:

var socketOpts = { 
                        reconnect: true,
                        reconnectionDelayMax : 2500,
                        timeout : 10000,
                        transport: ['polling','websocket']
                     };

    socket = io.connect( $scope.socket_addr, socketOpts );

    showMessage( true, "Aguardando conexão com o servidor!", true );

    /* Abaixo estão os eventos que o Socket pode disparar durante o funcionamento do app */

    /* Quando o Socket conectar no servidor */
    socket.on("connect", function() 
    {
        $scope.socket_connected = true;
        /* Agora que o socket já conectou, posso alterar o tempo de ping */
        socket.io.engine.pingInterval = 3000;
        socket.io.engine.pingTimeout = 5000;
        showMessage( false, "", false );
        console.log( "WS conectado" );
    });
4

1 回答 1

0

设置这些选项以延迟重新连接工作:-)

val opts = IO.Options()
opts.reconnection = true
opts.reconnectionDelay = 2000
opts.timeout = 60000
val socket = IO.socket(url, opts)

或者在离子

socketConf: {
    url: 'http://your.Server.url',
    options: { reconnection: true, reconnectionDelay: 3000, timeout: 60000 }
  }
于 2019-04-02T21:16:06.997 回答