IE10在握手后关闭连接。

4

我在libevent中实现了一个WebSocket服务器,虽然在Chrome和Firefox中没有任何问题,但在IE10中我甚至无法建立连接。

以下是握手过程:

IE10 Request:
GET /echo HTTP/1.1
Origin: 95.115.195.4
Sec-WebSocket-Key: rgPWUlUtk+h3CPWqk99OtA==
Connection: Upgrade
Upgrade: Websocket
Sec-WebSocket-Version: 8
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)
Host: 95.115.195.4:5555
Cache-Control: no-cache

Server Response:
HTTP/1.1 101 Switching Protocols
Upgrade: Websocket
Connection: Upgrade
Sec-WebSocket-Accept: jGmgQ/jOvew8MU9o3bbqPG9PHlY=
Sec-WebSocket-Protocol: chat

IE10调试器显示: SCRIPT12152:WebSocket错误:HTTP响应不正确。状态码101 有人知道我做错了什么吗? 谢谢
1个回答

5
客户端没有发送子协议列表,但您的服务器已将“chat”作为子协议值返回。根据IETF 6455 WebSocket规范第19页(第4.1节客户端要求)的说明:
6.  If the response includes a |Sec-WebSocket-Protocol| header field
   and this header field indicates the use of a subprotocol that was
   not present in the client's handshake (the server has indicated a
   subprotocol not requested by the client), the client MUST _Fail
   the WebSocket Connection_.

服务器只有在客户端发送 "Sec-WebSocket-Protocol: SUBPROTOCOL,..." 头到服务器时,才应该向客户端发送 "Sec-WebSocket-Protocol: SUBPROTOCOL" 头。请注意,客户端可以发送子协议列表,如果发送了子协议列表,则服务器必须从中选择一个进行响应。
Firefox 和 Chrome 可能过于宽松,没有遵循当前规范的版本。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接