我一直在网上搜索我在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" );
});发布于 2019-04-03 05:16:07
设置这些选项以延迟重新连接工作:-)
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 }
}https://stackoverflow.com/questions/53102726
复制相似问题