A self hosted application doesn't seem to run off of IIS, so does it require a specific operating system in order to enable web sockets on the server side?
SignalR uses the new WebSocket transport where available and falls back to older transports where necessary. While you could certainly write your app using WebSocket directly, using SignalR means that a lot of the extra functionality you would need to implement is already done for you.
- In Control Panel, click Programs and Features, and then click Turn Windows features on or off. Expand Internet Information Services, expand World Wide Web Services, expand Application Development Features, and then select WebSocket Protocol. Click OK. Click Close.
Browsers will support it because they have implemented the protocol internally, most browsers won't use the operating system transport libraries so they will be able to make use of WebSockets even if the OS does not directly support it.
HTTP.SYS prior to Windows 8/2012 has no built in support for WebSockets, so although .NET 4.5 contains WebSocket classes, they won't work unless you are running .NET 4.5+ on Windows 8/2012 and that will affect self-hosting solutions running in Windows < 8.
The implementation resides in the operating system code that .NET and IIS8 just leverages. The .NET classes simply wrap calls through to HTTP.SYS so it will throw an exception on an operating system that does not have underlying support for it.
When self-hosting you can however use your own internal Web Socket server such as Fleck and tell SignalR that you in fact do support Web Sockets regardless of your OS.
Start a Fleck server in your self-hosted application (examples on their site) and as an example you can do this for a PersistentConnection self-host:
public override Task ProcessRequest(HostContext context)
{
// Override what SignalR will be telling you internally and point to your own Web Socket Server.
context.Items[HostConstants.SupportsWebSockets] = true;
context.Items[HostConstants.WebSocketServerUrl] = "ws://localhost:3000";
return base.ProcessRequest(context);
}
Disclaimer: This is an undocumented feature, the developers of SignalR have told me that this may not be possible in future versions of the library. Keep in mind that you will also need to cater for keep-alives and serializing your data to JSON so it plays nice with the SignalR clients. It still works in version 1.1.3.
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