服务器:支持WebSocket的Windows Server 2012
客户端计算机1: Windows 8.1
客户端计算机2: Windows Server 2008R2
我使用SigalR客户端构建了一个C#应用程序,我可以在我的两台客户端机器上运行。但是,我遇到的问题是Client Machine 1
使用WebSockets连接,Client Machine 2
使用服务器端事件进行连接。
情况怎么样?显然,服务器支持WebSockets,因为Client Machine 1
可以使用它们进行连接。我不明白Client Machine 2
将如何使用SSE。
在我的客户端上使用hub.TraceLevel = TraceLevels.All;
,我看到了:
20:57:01.5805156 - null - ChangeState(Disconnected, Connecting)
20:57:02.1117656 - 7ff6f37a-2485-4f08-9c20-872f63964bee - WS Connecting to: wss://internal.soroco.com/signalr/connect?clientProtocol=1.4&transport=webSockets&connectionData=[{"Name":"ClientDaemonHub"}]&connectionToken=Mvbkw1czN7OZSE1jcfFjC2elxYxJhZiTZwisKKn6ZzYv%2BXRjOgfkclRJdSQtPi2wy%2F7XsUyxbCEXPMesFjvE7zh0FrcGwEsh6WTpHlkqB0rXyARnC42Op8ZO3w%2FhuKcB
20:57:02.1273906 - 7ff6f37a-2485-4f08-9c20-872f63964bee - 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__1.MoveNext()
20:57:02.1273906 - 7ff6f37a-2485-4f08-9c20-872f63964bee - SSE: GET https://internal.soroco.com/signalr/connect?clientProtocol=1.4&transport=serverSentEvents&connectionData=[{"Name":"ClientDaemonHub"}]&connectionToken=Mvbkw1czN7OZSE1jcfFjC2elxYxJhZiTZwisKKn6ZzYv%2BXRjOgfkclRJdSQtPi2wy%2F7XsUyxbCEXPMesFjvE7zh0FrcGwEsh6WTpHlkqB0rXyARnC42Op8ZO3w%2FhuKcB
20:57:02.1430156 - 7ff6f37a-2485-4f08-9c20-872f63964bee - SSE: OnMessage(Data: initialized)
20:57:02.1430156 - 7ff6f37a-2485-4f08-9c20-872f63964bee - SSE: OnMessage(Data: {"C":"d-752B7883-B,0|I,0|J,1","S":1,"M":[]})
20:57:02.4086406 - 7ff6f37a-2485-4f08-9c20-872f63964bee - ChangeState(Connecting, Connected)
20:57:03.5180156 - 7ff6f37a-2485-4f08-9c20-872f63964bee - OnMessage({"R":"497ca302-7375-4250-aa85-fb4ae2556877","I":"0"})
20:57:03.8461406 - 7ff6f37a-2485-4f08-9c20-872f63964bee - OnMessage({"I":"1"})
20:57:04.7523906 - 7ff6f37a-2485-4f08-9c20-872f63964bee - SSE: OnMessage(Data: {})
20:57:05.7523906 - 7ff6f37a-2485-4f08-9c20-872f63964bee - OnMessage({"I":"2"})
20:57:07.7367656 - 7ff6f37a-2485-4f08-9c20-872f63964bee - OnMessage({"I":"3"})
看起来相关的错误是:
自动:无法连接到使用传输webSockets。 System.PlatformNotSupportedException:此平台不支持WebSocket协议。
答案 0 :(得分:2)
Win7和Win2008 R2 doesn't support the ClientWebSocket
class上的.NET Framework 4.5,这就是SignalR客户端用于websocket传输的内容。由于使用websocket失败,客户端会回退到ServerSentEvents。