官术网_书友最值得收藏!

WebSockets

HTTP is a stateless protocol as noted previously. This means that a new connection is established for every request and closed after every response. An HTML5 WebSocket is a communication interface that allows for a permanent bidirectional connection between client and server.

A WebSocket is opened by the client through a GET request such as the following:

GET /chat HTTP/1.1 
Host: server.example.com 
Upgrade: websocket 
Connection: Upgrade 
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== 
Sec-WebSocket-Protocol: chat, superchat 
Sec-WebSocket-Version: 13 
Origin: http://example.com 

If the server understands the request and accepts the connection, its response would be as follows:

HTTP/1.1 101 Switching Protocols 
Upgrade: websocket 
Connection: Upgrade 
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= 
Sec-WebSocket-Protocol: chat 

The HTTP connection is then replaced by the WebSocket connection, and it becomes a bidirectional binary protocol not necessarily compatible with HTTP.

主站蜘蛛池模板: 迁安市| 天门市| 繁峙县| 吴堡县| 偏关县| 扎兰屯市| 高阳县| 伊宁市| 谢通门县| 托里县| 丰台区| 沽源县| 保康县| 湘阴县| 寿宁县| 沙河市| 墨竹工卡县| 忻城县| 汝城县| 班玛县| 桃园县| 孝义市| 遂溪县| 房产| 南阳市| 阜康市| 法库县| 汪清县| 济阳县| 石柱| 普兰店市| 惠州市| 汉川市| 福州市| 平远县| 南乐县| 永城市| 衡南县| 中牟县| 英德市| 保康县|