I am attempting to get websockets working in my dev environment:
- Visual Studio 2010
- Windows 7
- Signal R 0.51
- Latest Chrome / Firefox
Unfortunately the Javscript client is using long polling. When I force web-sockets on the client side I can't connect at all:
$.connection.hub.start({ transport: ['webSockets'] })
Server code is self-hosted and based on the sample and looks like:
static void Main(string[] args)
{
string url = "http://localhost:8081/";
var server = new Server(url);
// Map the default hub url (/signalr)
server.MapHubs();
// Start the server
server.Start();
Console.WriteLine("Server running on {0}", url);
// Keep going until somebody hits 'x'
while (true)
{
ConsoleKeyInfo ki = Console.ReadKey(true);
if (ki.Key == ConsoleKey.X)
{
break;
}
}
}
public class MyHub : Hub
{
public void Send(string message)
{
Clients.addMessage(message);
}
}
I've searched around and found nothing definitive. Do I need to specify some extra things, use Visual Studio 2012 or will this only work on Windows 8 / IIS 8?
In addition to the above solutions for troubleshooting WebSockets problems in SignalR, if you are inside a corporate network (or something similarly structured) it is likely that your proxies and firewalls will interfere with the handshake.
But, if you access it over SSL, the wrapper it provides protects it from this interference in many cases.
Based on this answer https://stackoverflow.com/a/9135334/700926 you will see that WebSocket support in SignalR relies on Windows 8 / IIS8 - the answer also points to a wiki page at SignalR's github page, however, that page does not exists anymore.
But, by cloning the wiki repo at github and go back some revisions you will see the documentation of the
SignalR.WebSockets
project which according to SignalR's github page, does not exist anymore - (which might explain why the wiki site is removed) - however, in a revision of the wikipage forSignalR.WebSockets
from February this year, it stated that:I have tried searching for newer information than what I have been able to provide above, but as far as I can tell, the SignalR wiki does not cover this topic explicitly in its current version.
Signal R does work also on Windows 7, IIS 7.5 and Visual Studio 2012. The only drawback is that it will use longPolling as transport protocol.
In order to succesfully use signalR with the above configuration we need to set up few things, which actually are not detailed in any of the signalR tutorials.
So, on server side (win 7, IIS 7.5) when you create the connection and the proxy you must do something like this:
Of course, on the client side in the same way you have to specify the transport protocol as being 'longPooling':
Even on Windows 8 / .NET 4.5 it was not working initially, but with these additional tips I finally got it working.
Install websocket support
in web.config, under appSettings, add this setting:
SignalR automatically negotiates websockets, it does not have to be specified and nothing special is needed in code.