1. 程式人生 > >Net 4.5 WebSocket 在 Windows 7, Windows 8 and Server 2012上的比較

Net 4.5 WebSocket 在 Windows 7, Windows 8 and Server 2012上的比較

Net 4.5 WebSocket 在 Windows 7, Windows 8 and Server 2012上的比較

.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?的相關討論,

原文  https://stackoverflow.com/questions/12073455/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, yet running a HttpListener and trying to access it using an open-source WebSocket implementation got me a "Portocol not supported" error

  •   

    While it is an interesting 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 or ASP.NET directly.

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 (etc) headers (from a Chrome session, as it helps).

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 is really 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.