0

I've tested many socket examples and communication between them was pretty simple: socket is opened and stays open until you close it and no information is being sent except the one you have sent.

With HTML5 web sockets these two moments are different.

At first, as soon as the client HTML5 socket connects to server socket it sends a bunch of information:

GET /echo HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: localhost:2002
Origin: null
Pragma: no-cache
Cache-Control: no-cache
Sec-WebSocket-Key: iYzsmhdzg6h6/UGtCLLGVA==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits, x-webkit-deflate-frame
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36
Cookie: _rails-socket-listener_session=dGtleFYxNjhIaUZrZVpOWUNIMHdFZFd6WW9wY2FJYjIwOWdSMFVPR1ZkYkZUakExdVlhNzMvWEphNG1IRUIvT1JsQ0N6bHF4REFXTkJUemE4R2RjOER6bXdhSEt6M0tIYmRwV0w3VzkrVGt4MzN2Z0M3MXMyYndZR3hvOGMySTJTZmdEMW9JdEE5ZERuSDB4VCtROFNnPT0tLTlheG1KamlBSVVmT0tUZ1F5bmQ0OUE9PQ%3D%3D--23413749a30295f08d277292837c76187a02a332

How to interpret this information? What to do with it?

At second, when I send some string from debugging server (Hercules setup utility), socket's onmessage event is not fired and client socket closes the connection immediately after this.

So, I suppose that HTML5 web socket expects some handshaking before it could be used. Where to read about it?

BTW: I am using Ruby as server-side language.

4

1 回答 1

1

我已经测试了许多网络套接字示例....

根据您的描述,您没有使用“网络套接字”,而只是使用“套接字”,例如直接 TCP/IP。WebSockets(例如你所说的“HTML web sockets”)是不同的:它们被用来创建一些socket,比如通过已建立的HTTP连接。因此,您会看到带有“Upgrade: websocket”标头、“Sec-WebSocket-Key”等的 HTTP 查询。

建立连接后(服务器发送响应代码为 101),WebSocket 连接具有自己的数据帧和加扰,因此您不能仅将其与普通套接字工具一起使用。

有关规范,请参阅https://www.rfc-editor.org/rfc/rfc6455 ,如果您查找更多文档、用法,请使用“WebSockets”作为关键字...

于 2014-06-04T19:06:19.903 回答