如何在socket.io中配置重新连接? [英] How configure reconnecting in socket.io?

查看:1041
本文介绍了如何在socket.io中配置重新连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下一个代码创建socket.io连接

I create socket.io connection with next code

var socket = new io.connect('http://localhost:8181', {
    'reconnect': true,
    'reconnection delay': 500,
    'max reconnection attempts': 50
});

但当我杀死服务器 CTRL + C 并再次启动时,重新连接没有发生。但在客户端提出了断开事件。这可能是什么原因?

But when I kill server CTRL+C and start it again, reconnection isn't happening. But disconnect event raised on client side. What maybe reason of it?

推荐答案

这是一个老问题,但对于像我这样的其他人,他们正在寻找如何配置重新连接在 socket.io(1.x)这里是一个正确的语法:

This is an old question, but for other people like me, who are looking how to configure reconnect in socket.io (1.x) here is a correct syntax:

var socket = new io.connect('http://localhost:8181', {
    'reconnection': true,
    'reconnectionDelay': 1000,
    'reconnectionDelayMax' : 5000,
    'reconnectionAttempts': 5
});

这篇关于如何在socket.io中配置重新连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆