Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR - Always downgraded to server sent events in Chrome/Firefox

I have an API application and a web application (for simplicity on the same server -- I'll do the CORS stuff later).

  • Windows Server 2012 with IIS 8.5
  • Websockets installed through "Programs and features"
  • Firewall turned off

The api is using owin + signalr and has the proper initialization (trimmed it down to find the error):

public void Configuration(IAppBuilder app)
{
    GlobalHost.Configuration.TransportConnectTimeout = TimeSpan.FromSeconds(5);
    app.MapSignalR();
    app.UseWebApi(Startup.CreateConfiguration());
}

private static HttpConfiguration CreateConfiguration()
{
    HttpConfiguration configuration = new HttpConfiguration();
    configuration.MapHttpAttributeRoutes();
    return configuration;
}

Everything seems to work perfectly except connection to the actual websockets. Every time the client tries to establish a connection, there is a timeout and it fails over to SSE (or forever frame/long polling in IE). I increased the timeout to 25 seconds and the same symptoms are occurring.

On the client, I consistently get this error with logging turned on:

SignalR: Connecting to websocket endpoint 'ws://[myurl]'.
SignalR: Websocket opened.
SignalR: **webSockets timed out when trying to connect.**
SignalR: Closing the Websocket.
SignalR: Attempting to connect to SSE endpoint 'http://[myurl]'.
SignalR: EventSource connected.
SignalR: serverSentEvents transport selected. Initiating start request.
SignalR: The start request succeeded. Transitioning to the connected state.

I have tried following the guides provided by the signalR team and I cannot see what I am missing.

Thanks for any help!

UPDATE: I downloaded a sample and ran it as-is on the server. Same situation, so this is likely a server configuration setting that I missed along the way. I still have not found what I missed.

like image 349
junkyspace Avatar asked Aug 27 '14 17:08

junkyspace


3 Answers

You need to enable WebSockets for the website in Server Manager.

http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support

like image 127
jonesy827 Avatar answered Oct 30 '22 02:10

jonesy827


Try establishing a SignalR connection from your Windows Server machine itself. This might have something to do with the network. Perhaps there's a proxy or something in between the client and server that doesn't properly support WebSockets.

like image 32
halter73 Avatar answered Oct 30 '22 00:10

halter73


If you are inside of a network with a "corporate" firewall, it can screw up the websockets handshake.

But, you can prevent this interference if you access your server over SSL. I've seen this first hand be the cause and solution multiple times for websockets problems in corporate environments.

like image 45
Bon Avatar answered Oct 30 '22 01:10

Bon