题
我确实在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
任何人都知道我做错了什么?
感谢
解决方案
客户端没有发送子协议列表,但您的服务器已将“聊天”作为子协议值发送。根据 ietf 6455 websocket spec (第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:sub间组”标题,如果客户端发送了“sec-websocket-protocol:substocol,...”标题到服务器,则将返回给客户端。请注意,客户端可以发送子协议列表,如果确实如此,服务器必须从列表中选择一个以响应。
可能是Firefox和Chrome太宽容,不遵守目前的规格版本。
不隶属于 StackOverflow