重新连接订阅集线器的连接会导致立即断开连接

时间:2012-09-25 14:25:14

标签: c# signalr

使用以下控制台应用

    static void Main(string[] args)
    {
        Thread connector = new Thread(Connector);
        connector.Start();

        while (true)
        {
            Thread.Sleep(500);
        }
    }

    private static void Connector()
    {
        SignalR.Client.Hubs.HubConnection connection = new SignalR.Client.Hubs.HubConnection("http://192.168.42.10:1327/Chat");

        SignalR.Client.Hubs.IHubProxy loginHub = connection.CreateProxy("LoginHub");

        connection.Received += connection_Received;
        connection.Reconnected += connection_Reconnected;
        connection.StateChanged += connection_StateChanged;
        connection.Error += connection_Error;
        connection.Closed += connection_Closed;

        connection.Start().Wait();
    }

LoginHub实现了IDisconnect。

如果我启动应用程序,请让它连接,拉动网络电缆,等待服务器端断开事件触发,重新连接网络电缆,客户端将重新连接,然后立即关闭其连接。

如果在服务器端断开连接之前拔下并重新插入网络电缆,则连接重新连接正常。

这是预期的行为吗?重新连接应该如何工作?

1 个答案:

答案 0 :(得分:2)

EDITED(重新阅读并看到我不清楚):当客户端立即与SSE断开连接时,在大多数情况下(在0.5.3中)它将被抛入无限重新连接循环(参见下面的错误) )。

但是,在某些情况下,它会重新连接然后立即断开连接,这是故意的行为。我们强制客户端断开连接的原因是因为此时服务器完全忘记了客户端。因此客户端需要通过$ .connection.hub.start等重新实例化它的连接。

在下一个版本中,我们修复了无限重新连接问题,并且还向流程添加了“警告”,以通知开发人员服务器可能已关闭(onConnectionSlow)。如果您成功重新连接并且服务器忘记了您,则会被告知您断开连接。

以下是对bug的引用: https://github.com/SignalR/SignalR/issues/687