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?
ASP.NET Core SignalR is a library that simplifies adding real-time web functionality to apps. It uses WebSockets whenever possible. For most applications, we recommend SignalR rather than raw WebSockets.
SignalR can be used together with Web API just fine, so some functionality in application which is not realtime and doesn't require persistent connection could be served by Web API.
A SignalR uses a transport medium such as WebSocket to communicate between server and client. A SignalR connection starts as HTTP and is then promoted to a WebSocket connection if available. WebSocket is the ideal transport for SignalR.
Solution 1Check that all the Bot Insight services are running. Check that your firewall settings are configured to accept incoming websocket data. Try to use a different web browser. Restart the Bot Insight Visualization and Bot Insight Scheduler services.
Make sure it is enabled on the dev server.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With