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:
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/websocket#windows-server-2012-or-windows-server-2012-r2
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/websocket#how-to-configure-websocket
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:
https://stackoverflow.com/a/37531108/177416
https://github.com/SignalR/SignalR/issues/3148
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.
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.
Related
I am trying to use the same port on the same host.
Websocket URL
ws://aaa.bbb.cc.ddd:eeee/ws
HTTP URL
http://aaa.bbb.cc.ddd:eeee/docs
But when I open the "http://aaa.bbb.cc.ddd:eeee/docs" page, I get this error message.
Failed to open a WebSocket connection: invalid Connection header: keep-alive.
You cannot access a WebSocket server directly with a browser. You need a WebSocket client.
Http does not work. But, websocket is connected normally.
How can I solve this problem?
The WebSocket protocol is not the HTTP protocol.
Although the WebSocket protocol does initiate a new connection using an HTTP request, it quickly upgrades the connection to full WebSocket (which requires a Connection: upgrade header in the initial request, not Connection: keep-alive).
You can't use a vanilla web browser to directly communicate with a WebSocket URL, as such a browser doesn't know how to finish the upgrade, let alone process any WebSocket packets. So, you must use a valid WebSocket client (such as the WebSocket API that modern browsers expose to client-side scripting).
I am using a SignalR Client connection using HubConnection. When calling Start(), an System.Net.WebException is thrown with the following message:
The remote server returned an error: (400) Bad Request.
The server response is:
Not a valid web socket request.
I am running Windows Server 2012 R2 with IIS 8.5
What could be the problem?
The problem was with the configuration of IIS.
You have to install the WebSocket Protocol support in order to connect to SignalR using WebSockets.
The problem is this:
I decided to make a messenger/chat (VCL application) with callback on DataSnap technology (IDE Delphi XE6), has created a simple DataSnap server (tcp / ip + http) without the database, and thick client.
All works fine if the whole thing run on a local network (tcp / ip) or via the Internet (http).Problems arise when run over HTTP and the client machine has a HTTP proxy server, the client application can not connect to my DataSnap server application. Client application gets error "10061 connection refused"
or "Expected datasnap context in request http://[YourServerIP]:[YourPort]/datasnap/tunnel".
I tried to enter IP and port of the proxy server to params of component TSQLConnection.Driver params DSProxyHost and DSProxyPort, turned off my firewall and antivirus software, checked allows traffic to the proxy ip + port, but the problem has not disappeared.
After few days searches, without results, i decided listening requests from client application and response of my DataSnap Server application in HTTPTrace procedure of DSHTTPService1 component, also with software HTTPDebugerPro, and i noticed interesting thing:
when client app connecting to ds server app without proxy server, in request ds server app receive URI with this text "/datasnap/tunnel" and all works fine ds server response "200, OK".
when client app connecting to ds server app with proxy, in request ds server app receive URI with text "http://[YourServerIP]:[YourPort]/datasnap/tunnel" and raised exception with response error "404, Expected datasnap context in request http://YourServerIP:YourPort/datasnap/tunnel".
Has anyone knows solution about this problem? How to connect DataSnap client to DataSnap server via proxy server? I searched solution for this problem several days, I shoveled the Internet but have not yet found a solution.
I have a web socket server hosted in ASPNET Core RC2.
It works fine on my local dev box, when running on just kestrel, and also when kestrel is hosted in IIS.
When Google Chrome is used to connect to the websocket server, it works OK on local box, and on remote box:
JavaScript:
new WebSocket("wss://myServer:8087")
However when the JavaScript is connecting to the same server, hosted on our build machine (OS: Server 2008 R2) the client gets this 302 (redirect) error:
WebSocket connection to 'wss://myBuildServer:8087/' failed: Error during
WebSocket handshake: Unexpected response code: 302
note: when the JavaScript is running on Chrome on the server itself, the error is different:
WebSocket connection to 'wss://xxx:8087/' failed: WebSocket opening handshake was canceled
C# source that adds web sockets (Microsoft.AspNetCore.WebSockets.Server 0.1.0-rc2-final):
private void ConfigureWebSockets(IApplicationBuilder app)
{
DPT2.Web.Utils.Logger.Log("ConfigureWebSockets()");
_socketHandler = new Sockets.WebSocketHandler(_nodeServices);
app.UseWebSockets(new WebSocketOptions{
//try to fix 302 redirect on build m/c:
ReplaceFeature = true,
//TODO tune via these params:
KeepAliveInterval = TimeSpan.FromMinutes(2),
ReceiveBufferSize = 4 * 1024
});
app.Use(async (http, next) =>
{
if (http.WebSockets.IsWebSocketRequest)
{
var webSocket = await http.WebSockets.AcceptWebSocketAsync();
if (webSocket != null && webSocket.State == WebSocketState.Open)
{
await _socketHandler.Handle(webSocket);
}
}
else
{
// Nothing to do here, pass downstream.
await next();
}
});
}
It looks like the request is being 'corrupted' somehow, and this C# line does not recognise it as a web socket request, and so passes it on to MVC:
if (http.WebSockets.IsWebSocketRequest)
versions:
Server OS: Windows 2008 R2
IIS 6.1 build 7601 - SP1
IIS Manager 7.5.7600.16385
installed the ASPNET Core hosting: DotNetCore.1.0.0.RC2-WindowsHosting.exe
I've tried a few workarounds:
using http for the site, and ws:// for the web socket URL
using https for the site, and wss:// for the web socket URL
adding the ReplaceFeature option to the websocket server
Has anyone else seen a similar issue ?
I think its to do with IIS acting as a reverse proxy for kestrel, and perhaps on that particular machine, the proxying is messing up the web socket request ...
It could be a configuration issue on the server ...
Sean
$.connection.hub.start().done takes 5 seconds to startup in production, works fine in dev.
Server 2012 and IIS 7.5
I remember another user had the same problem
Hub.start - wait for finish
I had the same issue
SignalR tried to connect to WebSocket but fails or your server does not have WebSocket Protocol for IIS installed.
Then it tries to use serverSentEvents and it returned timeout after 5 second
Only then it established longPolling
Thus you can try install WebSocket Protocol or remove serverSentEvents from transport options