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

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.

主站蜘蛛池模板: 拜泉县| 平陆县| 章丘市| 阿城市| 江口县| 定兴县| 长葛市| 林芝县| 晋中市| 大余县| 自治县| 吉林市| 炎陵县| 双柏县| 习水县| 东山县| 平度市| 高密市| 嘉鱼县| 谷城县| 万源市| 浑源县| 辽中县| 杭州市| 阿城市| 北票市| 监利县| 石河子市| 青海省| 清新县| 安徽省| 石首市| 大丰市| 定日县| 永新县| 宜川县| 湖口县| 民勤县| 靖安县| 白朗县| 家居|