Reputation: 35781
I'm trying to get Web Sockets working as the protocol with an ASP.NET 4.8 Framework app that uses SignalR 2.4.2. It works fine with Visual Studio 2019 on localhost, running Windows 10 Pro. It fails on a Windows 2016 server (not Azure) with this error in Chrome 85:
signalr?v=igzza46L1gfiUBzl96WDUmuI9_CUHV_qqd0Kd-fDr8A1:1 WebSocket connection to 'wss://someServer.org/signalr/connect?transport=webSockets&clientProtocol=2.1&connectionToken=...&connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D&tid=0' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
and
No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.
at Object.error (signalr?vv=...:1)
at g (signalr?vv=...:1)
at v (signalr?vv=...:1)
at h.transportFailed (signalr?vv=...:1)
at signalr?vv=...:1
at WebSocket.e.socket.e.socket.onclose (signalr?vv=...:1)
Opening this URL on the server https://myserver.org/signalr/negotiate
to get the SignalR details produces the following:
Url "/signalr"
ConnectionToken "..."
ConnectionId "..."
KeepAliveTimeout 20
DisconnectTimeout 30
ConnectionTimeout 110
TryWebSockets true
ProtocolVersion "1.2"
TransportConnectTimeout 5
LongPollDelay 0
Here's the chain of console responses in Firefox for the failed call:
SignalR: Client subscribed to hub 'myhub'.
SignalR: Negotiating with '/signalr/negotiate?clientProtocol=2.1&connectionToken=...&connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D'.
SignalR: webSockets transport starting.
SignalR: Connecting to websocket endpoint 'wss://myServer.org/signalr/connect?transport=webSockets&clientProtocol=2.1&connectionToken=...%3D%3D&connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D&tid=8'
Firefox can’t establish a connection to the server at wss://myServer.org/signalr/connect?transport=webSockets&clientProtocol=2.1&connectionToken=...&connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D&tid=8.
SignalR: Websocket closed.
SignalR: Closing the Websocket.
SignalR: webSockets transport failed to connect. Attempting to fall back.
SignalR: No fallback transports were selected.
SignalR: Stopping connection.
SignalR: Fired ajax abort async = true.
WebSockets has been installed on the server using these instructions:
On the client, it's using the following:
$.connection.hub.logging = true;
$.connection.hub.start({ transport: ['webSockets'] })
.done(function () {
// ...
}).fail(e => {
console.log(e);
});;
In addition, BrowserLink is disabled in Visual Studio, as that's been mentioned as a possible cause of issues.
Additional articles researched:
Some suggested removing the Application_PreSendRequestHeaders
from Global.asax.cs
but this didn't change anything on the server.
I'm aware that SignalR supports other protocols but I'm trying to get Web Sockets working.
Thanks.
Update: The web sockets protocol also works on the localhost of the server itself, logging in via RDP and using a browser to open the page.
Upvotes: 6
Views: 8873
Reputation: 35781
This was a tough nut to crack. Working with the system admins, we discovered it was caused by the load balance/proxy level, which sits in front of all our traffic. By default, it didn't support web sockets. Once web sockets were enabled, SignalR was happy.
Upvotes: 6