does self hosted signalr require windows server 20

2019-01-17 08:50发布

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
3条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-17 09:12

Yes it requires windows server 2012 check the quote below from SignalR Supported Platforms

The SignalR server component can be hosted in the following server or client operating systems. Note that for SignalR to use WebSockets, Windows Server 2012 or Windows 8 is required (WebSocket can be used on Windows Azure Web Sites, as long as the site's .NET framework version is set to 4.5, and Web Sockets is enabled in the site's Configuration page).

Also a good read on why can be found here

查看更多
虎瘦雄心在
3楼-- · 2019-01-17 09:33

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.

查看更多
来,给爷笑一个
4楼-- · 2019-01-17 09:35

I've know for sure that websockets are not supported now by doing a quick test. I created a self hosted hub and then a quick jquery client. On my windows 8 machine the querystring showed websockets, on the server 2008 r2 it showed long polling...

查看更多
登录 后发表回答