Connecting to IIS 8 from Safari 5.1.7 by WebSocket

2019-09-02 18:09发布

问题:

My IE, Chrome, Chrome androud, Opera, Firefox browsers successfully connected to my IIS by WebSocket. See an example:

The handshake from the client looks as follows:

GET /SimpleChatApplication/ChatHandler.ashx HTTP/1.1

Host: pc2014:80

Connection: Upgrade

Pragma: no-cache

Cache-Control: no-cache

Upgrade: websocket

Origin: http//pc2014

Sec-WebSocket-Version: 13

User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36

Accept-Encoding: gzip, deflate, sdch

Accept-Language: ru,en;q=0.8,en-US;q=0.6

Sec-WebSocket-Key: rrKYVVaPKmMnINtsUh9BNg==

Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

The handshake from the server looks as follows:

HTTP/1.1 101 Switching Protocols

Cache-Control: private

Upgrade: Websocket

Server: Microsoft-IIS/8.5

X-AspNet-Version: 4.0.30319

Sec-WebSocket-Accept: IQ/qcgyu36N/d1p0JEU7nZ3W8Vo=

Connection: Upgrade

X-Powered-By: ASP.NET

Date: Wed, 16 Sep 2015 23:54:37 GMT

But if I use Safary bowser then:

The handshake from the client looks as follows:

GET /SimpleChatApplication/ChatHandler.ashx HTTP/1.1

Upgrade: WebSocket

Connection: Upgrade

Host: pc2014:80

Origin: http://pc2014

Sec-WebSocket-Key1: N9 Q32K\275z 5z < 1= 2 c

Sec-WebSocket-Key2: -1 z 6#HA g)1Aue0483 420d

The handshake from the server looks as follows:

HTTP/1.1 200 OK

Cache-Control: private

Server: Microsoft-IIS/8.5

X-AspNet-Version: 4.0.30319

X-Powered-By: ASP.NET

Date: Wed, 16 Sep 2015 23:56:19 GMT

Content-Length: 0

HTTP/1.1 400 Bad Request

Content-Type: text/html; charset=us-ascii

Server: Microsoft-HTTPAPI/2.0

Date: Wed, 16 Sep 2015 23:56:19 GMT

Connection: close

Content-Length: 326


Bad Request

Bad Request - Invalid Verb

HTTP Error 400. The request verb is invalid.


Please explain me where is error? Or Safary sends incorrect request, or IIS recognizes incorrectly.

I have used www.websocket.org site for testing. I have replaced the server address from "ws://echo.websocket.org" to my IIS address before testing

回答1:

It seems that Safari implements an old version of the WebSocket standard, named hybi.

Apparently ASP.NET only supports the definitive one, RFC6455. That is the version that major browsers use as well.



回答2:

Use the SignalR library. ASP.NET SignalR is a new library for ASP.NET developers that makes it incredibly simple to add real-time web functionality to your applications. What is "real-time web" functionality? It's the ability to have your server-side code push content to the connected clients as it happens, in real-time.