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

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.

主站蜘蛛池模板: 元阳县| 都匀市| 泾阳县| 眉山市| 凤庆县| 昌宁县| 句容市| 和林格尔县| 瓦房店市| 哈密市| 普定县| 平湖市| 甘孜| 沅陵县| 兰溪市| 丹巴县| 宁德市| 盱眙县| 东乌| 平舆县| 宁南县| 丽江市| 清徐县| 万载县| 噶尔县| 鄯善县| 满城县| 沭阳县| 安达市| 武平县| 台东县| 徐水县| 山阳县| 临桂县| 文登市| 渑池县| 巨野县| 安乡县| 长垣县| 靖安县| 安吉县|