有人读过 Hickson 2010 年 5 月的 draft-hixie-thewebsocketprotocol-76 WebSocket 协议吗?
这是 .htm 文件的来源:
<html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var socket = new WebSocket('ws://localhost:8181/websession');
socket.onopen = function() {
alert('handshake successfully established. May send data now...');
};
socket.onclose = function() {
alert('connection closed');
};
</script>
</head>
<body>
</body>
</html>
如果我有一个监听 8181 的 TCP 端口,这是我在 Chrome 中加载上述 .htm 文件时收到的请求:
GET /websession HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: localhost:8181
Origin: null
[\n]
(其中 [\n] 是 CRLF 字符。)
我应该回到这个握手开瓶器?Draft-hixie-thewebsocketprotocol-76 显示:
HTTP/1.1 101 WebSocket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Origin: http://example.com
Sec-WebSocket-Location: ws://example.com/demo
Sec-WebSocket-Protocol: sample
8jKS'y:G*Co,Wxa-
但是,此响应会导致socket.onclose
触发。