Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

does self hosted signalr require windows server 2012 in order to use websockets?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...