简体   繁体   English

Socket.IO客户端无法在3g / 4g连接上正常工作

[英]Socket.IO Client doesn't work properly on 3g/4g connection

I've been searching over the web about the problem I'm having with socketio client on 3g/4g networks. 我一直在网上搜索有关3g / 4g网络上的socketio客户端遇到的问题。 It seems to connect, but doesn't keep connected for long, it keeps connected for about 60 seconds then disconnect, connecting again when the reconnecting attempt events trigger, but reepats the above behavior. 它似乎已连接,但并没有保持长时间连接,它保持连接约60秒钟,然后断开连接,并在重新连接尝试事件触发时再次连接,但重新出现了上述行为。

Does anyone know why this happens or how to solve it? 有谁知道为什么会这样或如何解决呢?

Thanks in advance! 提前致谢!

Heres a sample of the code i'm using to start 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" );
    });

Setting these options to delay the reconnection worked :-) 设置这些选项以延迟重新连接的工作:-)

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

Or in Ionic 或在离子

socketConf: {
    url: 'http://your.Server.url',
    options: { reconnection: true, reconnectionDelay: 3000, timeout: 60000 }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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