.Net 4.5 WebSocket Server Running on Windows 7?

Net 4.5 WebSocket Server 可以运行在 Windows 7,但是Net 4.5的 ClientWebSocket 不支持 Windows 7,只支持 Windows 8 and Server 2012,但是可以使用第三方类库来支持Net 4.5 WebSocket 在win7,Windows 7上使用,如:

 

下面 来自  .Net 4.5 WebSocket Server Running on Windows 7?的相关讨论,


I know the ClientWebSocket class of .Net 4.5 is not supported on Windows 7, but is it possible to create a WebSocket server running on Windows 7 using the .Net 4.5 API?

To make myself clearer, according to both ​​here​​​ and ​​here​​, it looks like the server side part of the .Net 4.5 WebSocket implementation should be supported even on Windows 7,

  • While it is aninteresting question, it doesn't show much effort. What have you tried? According to MSDN indeed only Windows 8 and Server 2012 are supported. Do you require .NET built-in support? Otherwise there are various third-party libraries that suit your requirements. – ​​CodeCaster​​ Aug 22 '12 at 12:54

2 Answers

 

 

up vote34down voteaccepted

The OS-level HTTP.SYS support for websockets is limited to Win8 / Windows Server 2012 - which I agree is silly (it should be part of a windows-update, or a service-pack at most, IMO).

This means that you can't use the framework support for WebSockets from ​​HttpListener​

But: as for "is it possible to create a WebSocket server" - sure... but only if you handle the TCP/IP comms yourself, or use a 3rd-party library for the same. This is a little annoying, but is not as bad as it might sound.

Edit: after some checking, I can confirm that the server-side components for this do not work on Windows 7 (etc); the ​​IsWebSocketRequest​​​ returns ​​false​​ even though it is a web-socket request with ​​Connection: Upgrade​​​ and ​​Upgrade: websocket​

I am, however, very surprised to find that the client-side pieces don't work, because: that is simpler and doesn't (or at least, doesn't need to) involve HTTP.SYS. Trying to use them throws a ​​PlatformNotSupportedException​​.

  

answered

  • 1

    @sternr I don't think they are; I think it'll error at runtime. What is even more interesting: I was under the impression that​​ClientWebSocket​​ was supported on Win7 etc, since it doesn't depend on HTTP.SYS! – ​​Marc Gravell♦​​ Aug 22 '12 at 13:18
  • 1

    @sternr did some more research / testing on that; answer stands. –​​Marc Gravell♦​​ Aug 22 '12 at 13:49
  • 7

    @sternr it is bizarre from my point of view too. I'm very disappointed by this,especially the client-side pieces. Meh, no actually I'm disappointed by the server-side pieces too. – ​​Marc Gravell♦​​ Aug 22 '12 at 13:52
  • 2

    Both the client-side and the server-side pieces depend on an OS-level component (websocket.dll), and this component only ships with Windows 8 / Server 2012. I am unsure of why this component cannot run downlevel, but the dependency explains the behavior you are seeing. –​​Levi​​ Aug 24 '12 at 6:13
  • 4

    Yeah, honestly, who thinks this isreally a technical issue. – ​​Craig​​ Dec 3 '13 at 1:58

 

up vote6down vote

As Marc says, the Microsoft APIs do not work on Windows 7. However there are several open source libraries that support WebSockets on Windows 7, and in some cases even cross platform via Mono.

龙腾一族至尊龙骑