Nick
Nick

Reputation: 4223

SignalR Not Using Web Sockets

I'm having problems getting a site using SignalR to actually use web sockets. It's an intranet application built with ASP.NET MVC.

For testing I put together the simple chat application from the ASP.NET site using SignalR v2.1.2.

I put this on one of our dev servers (Windows Server 2012, IIS8, .NET 4.5.1) and I'm using Chrome on Windows 7.

Looking in the Network tab of the Chrome dev tools it's connecting with ServerSentEvents. The negotiation call looks like this

ConnectionId: "eee14afe-6598-492e-81ae-f14b98041474"
ConnectionTimeout: 110
ConnectionToken: "1iDREVWa++NL0Cj95i++QOufi+1+ywZlY1Tsrv7t06zqca5wn6nvPRLJQOd8/I7EPEaDGabP1MfqhoR/Q2D1vFK6bdujXdFoxGYF XlZ00AHLw9qjDuDgyx3+6a7qXHGFKp6ag6zu4TGuuW9sqM/nkw=="
DisconnectTimeout: 30
KeepAliveTimeout: 20
LongPollDelay: 0
ProtocolVersion: "1.4"
TransportConnectTimeout: 5
TryWebSockets: false
Url: "/Chat/signalr"

I then copied the same application to a production server, again Windows 2012 Server, IIS8, ,NET 4.5.1.

This time the application connects using Web Sockets and the negotiation call looks like this:

ConnectionId: "27484ca2-2935-43fd-a6eb-ae13f7fdbd54"
ConnectionTimeout: 110
ConnectionToken: "AhL+5jrvoHa0FXdU+Zg3dJ4a3Avfw28aOZN7raTHpYxUte4GA5Ru9ZmdDZMtCZOFbnpGzOmktY56jH2Tbz+I7g3OO5RnMlBBn8CSg5Il8fb0p/faK1ShGbWhFOKBe9Ns"
DisconnectTimeout: 30
KeepAliveTimeout: 20
LongPollDelay: 0
ProtocolVersion: "1.4"
TransportConnectTimeout: 5
TryWebSockets: true
Url: "/Chat/signalr"

For an unknown reason, the TryWebSockets is True this time.

Can anyone tell me why the in the first instance it's not trying to use Web Sockets? Could it be IIS configuration? I made sure both instances had the same settings in their app pools.

Could it be firewall issues? The two servers are in different parts of the network, but I'm not sure what the differences are. Perhaps it's a router issue?

The apps were tested in Chrome v38 and IE 11.

Any thoughts / trouble shooting steps are welcome, please.

EDIT:

Ok, I enabled tracing on the server and in the javascript following this article on the ASP.NET site

The server generates a transports log file with the following content:

SignalR.Transports.TransportHeartBeat Information: 0 : Connection 6b0193e6-bde6-4130-b4da-178fd24a786a is New.
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(6b0193e6-bde6-4130-b4da-178fd24a786a)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(6b0193e6-bde6-4130-b4da-178fd24a786a)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(6b0193e6-bde6-4130-b4da-178fd24a786a)
SignalR.Transports.ServerSentEventsTransport Information: 0 : Abort(6b0193e6-bde6-4130-b4da-178fd24a786a)
SignalR.Transports.TransportHeartBeat Information: 0 : Removing connection 6b0193e6-bde6-4130-b4da-178fd24a786a
SignalR.Transports.ServerSentEventsTransport Information: 0 : End(6b0193e6-bde6-4130-b4da-178fd24a786a)
SignalR.Transports.ServerSentEventsTransport Verbose: 0 : DrainWrites(6b0193e6-bde6-4130-b4da-178fd24a786a)
SignalR.Transports.ServerSentEventsTransport Information: 0 : CompleteRequest (6b0193e6-bde6-4130-b4da-178fd24a786a)

And on the client the following appears in the javascript console:

SignalR: Client subscribed to hub 'chathub'. jquery.signalR-2.1.2.min.js:8
SignalR: Negotiating with '/Chat/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D'. jquery.signalR-2.1.2.min.js:8
SignalR: Attempting to connect to SSE endpoint 'https://att15web95/Chat/signalr/connect?transport=serverSentEvents&clientPr…mPZV2icA%3D%3D&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&tid=7'. jquery.signalR-2.1.2.min.js:8
SignalR: EventSource connected. jquery.signalR-2.1.2.min.js:8
SignalR: serverSentEvents transport selected. Initiating start request. jquery.signalR-2.1.2.min.js:8
SignalR: The start request succeeded. Transitioning to the connected state. jquery.signalR-2.1.2.min.js:8
SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332 and a connection lost timeout of 20000. jquery.signalR-2.1.2.min.js:8
SignalR: Invoking chathub.Send jquery.signalR-2.1.2.min.js:8
SignalR: Triggering client hub event 'addNewMessageToPage' on hub 'ChatHub'. jquery.signalR-2.1.2.min.js:8
SignalR: Invoked chathub.Send jquery.signalR-2.1.2.min.js:8

Is there anything there that tells me why SignalR is not using Websockets?

Upvotes: 11

Views: 15122

Answers (5)

dove
dove

Reputation: 20674

Make sure it is enabled on the dev server.

  • On the taskbar, click Server Manager.
  • In Server Manager, click the Manage menu, and then click Add Roles and Features.
  • In the Add Roles and Features wizard, click Next. Select the installation type and click Next.
  • Select the destination server and click Next.
  • On the Server Roles page, expand Web Server (IIS), expand Web Server, expand Application
  • Development, and then select WebSocket Protocol. Click Next.
  • On the Select Features page, click Next.
  • On the Confirm installation selections page, click Install.
  • On the Results page, click Close.

Taken from: http://www.iis.net/configreference/system.webserver/websocket

Also to reset IIS after this.

As @Luke points out you can use this one liner of powershell

Install-WindowsFeature -name Web-WebSockets

Upvotes: 23

Mr. Kraus
Mr. Kraus

Reputation: 8135

look at the answer in this post

SignalR w/ Web Sockets

If the client is not running Windows 8 or higher, you can't use WebSockets, apparently...

Upvotes: 1

avalizada
avalizada

Reputation: 11

To fix it you need following in the web.config:

<system.web>
   <compilation debug="true" targetFramework="4.5"/> 
   <httpRuntime targetFramework="4.5"/>
   <pages controlRenderingCompatibilityVersion="4.0"/> 
</system.web>

Upvotes: 0

shmuel friedman
shmuel friedman

Reputation: 81

On Windows 7/8 you will go to:

  • Control Panel
  • Programs
  • Turn Window Features on or off
  • Internet Information Services
  • World Wide Web services
  • Application Development Features
  • WebSocket Protocol
  • Make sure the checkbox is checked
  • Click Ok etc.

Upvotes: 0

Bon
Bon

Reputation: 1091

Ensuring you connect over SSL will prevent proxies and firewalls from disrupting the WebSockets handshake. I had very similar symptoms as you described and SSL fixed it for me. Even self signed cert will work, if you're not easily able to get one signed or loaded onto your local store from your network admin for your domain.

Upvotes: 1

Related Questions