SignalR .NET客户端超时

以下是我们的设置:

在Windows Server 2012上

  • SignalR Server(ASP.NET MVC应用程序) .

  • Sencha HTML5应用程序(SignalR客户端)位于同一服务器(Windows Server 2012)上 .

  • Windows Server 2008 R2服务器上的.NET Windows服务 . 这也充当SignalR客户端 .

我们使用几周前的SignalR开发版本(1.1.0) . 偶尔,我们发现SignalR服务器失去了与.NET客户端的连接 . 使用最新版本允许我们添加客户端日志记录 .

我们在上周四(2013年3月28日下午6点33分)有一个很好的例子 .

客户端日志(为简洁起见,我删除了任何不重要的日志) . 请注意,Hub类称为“Transmitter” .

ChangeState(New connection, Disconnected, Connecting)
WS: wss://www.myURL.com/SignalRServer/signalr/connect?transport=webSockets&connectionToken=fsfY8BWv5eiSNuQtHW6wfY6XWDInkrVEn5fyHogSIyapob1BxoZLz0aMO_IuARmd9suam3my3yU0sQOEYMah-ZVj_4idQHXKQmhUKyRFlNgObCWlblCDfXflOq4Fxt8P0&connectionData=[{"Name":"Transmitter"}]
Auto: Failed to connect to using transport webSockets. System.PlatformNotSupportedException: The WebSocket protocol is not supported on this platform.
   at System.Net.WebSockets.ClientWebSocket..ctor()
   at Microsoft.AspNet.SignalR.Client.Transports.WebSocketTransport.<PerformConnect>d__0.MoveNext()
SSE: GET https://www.myURL.com/SignalRServer/signalr/connect?transport=serverSentEvents&connectionToken=fsfY8BWv5eiSNuQtHW6wfY6XWDInkrVEn5fyHogSIyapob1BxoZLz0aMO_IuARmd9suam3my3yU0sQOEYMah-ZVj_4idQHXKQmhUKyRFlNgObCWlblCDfXflOq4Fxt8P0&connectionData=[{"Name":"Transmitter"}]
ChangeState(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Connecting, Connected)
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: initialized)
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {"C":"B,25|1,0|2,0|3,0","M":[{"H":"Transmitter","M":"joined","A":["0e3cd780-9efc-4824-b9a2-bae81b9be17f","27/03/2013 8:16:46 PM"]}]})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {"C":"B,25|1,1|2,0|3,0","M":[{"H":"Transmitter","M":"isLoggedIn","A":[true]}]})
OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, {"I":"0"})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
............
............
............
............
............
............
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
Connection Timed-out : Transport Lost Connection 28/03/2013 8:33:14 AM
ChangeState(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Connected, Reconnecting)
SSE: GET https://www.myURL.com/SignalRServer/signalr/?transport=serverSentEvents&connectionToken=fsfY8BWv5eiSNuQtHW6wfY6XWDInkrVEn5fyHogSIyapob1BxoZLz0aMO_IuARmd9suam3my3yU0sQOEYMah-ZVj_4idQHXKQmhUKyRFlNgObCWlblCDfXflOq4Fxt8P0&messageId=B%2C6&connectionData=[{"Name":"Transmitter"}]
ChangeState(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Reconnecting, Connected)
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: initialized)
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {"C":"B,7","M":[{"H":"Transmitter","M":"rejoined","A":["0e3cd780-9efc-4824-b9a2-bae81b9be17f","28/03/2013 6:33:12 PM"]}]})
OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, {"I":"12"})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
............
............

在连接超时之前,一切都按预期工作 - SignalR服务器可以调用.NET客户端的方法,反之亦然 . 连接超时后,.NET客户端可以调用服务器Hub方法,但服务器无法调用.NET客户端方法 .

其他注意事项:

  • 请注意,连接超时报告"28/03/2013 8:33:14 AM"作为时间 . 这与后续条目中记录的时间不同,时间实际上是下午6:33:14(澳大利亚东部时间) .

  • 如上所示,ServerSentEvents用作SignalR .NET客户端在Windows 2008服务器上 .

  • 超时没有模式 . 有时它不会发生几天,有时则会在几个小时内发生 .

  • 超时与重启,IIS重置等机器(SignalR服务器或SignalR客户端所在的机器)无关 .

此外,这与瞬时连接损耗和重新连接完全不同,这似乎按要求工作 . 连接瞬间丢失的一个例子如下所示:

SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
ChangeState(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Connected, Reconnecting)
SSE: GET https://www.myURL.com/SignalRServer/signalr/?transport=serverSentEvents&connectionToken=fsfY8BWv5eiSNuQtHW6wfY6XWDInkrVEn5fyHogSIyapob1BxoZLz0aMO_IuARmd9suam3my3yU0sQOEYMah-ZVj_4idQHXKQmhUKyRFlNgObCWlblCDfXflOq4Fxt8P0&messageId=B%2C1D%7CF%2CE%7CG%2C0%7CH%2C0&connectionData=[{"Name":"Transmitter"}]
ChangeState(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Reconnecting, Connected)
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {"C":"B,2","M":[{"H":"Transmitter","M":"rejoined","A":["00fabf13-eb07-4704-8d43-4d8865a519f0","28/03/2013 4:08:26 PM"]}]})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: initialized)
OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, {"I":"11"})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})

我不明白为什么瞬间连接丢失和重新连接似乎有效,但连接超时后的重新连接不起作用 .

有什么办法可以解决这个问题吗?

提前致谢 .

回答(1)

2 years ago

当客户端的Disconnected事件被引发时,意味着服务器已删除连接 . 发生这种情况后,由开发人员重新启动连接 .

我们这样做是因为长时间在服务器上保持状态是昂贵的 .