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

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.

主站蜘蛛池模板: 游戏| 卓资县| 遵化市| 开化县| 金湖县| 阿城市| 依安县| 丰镇市| 宣威市| 博爱县| 邮箱| 定边县| 奉节县| 朔州市| 祁连县| 西林县| 邵武市| 深水埗区| 夹江县| 沙河市| 竹山县| 林芝县| 朔州市| 无锡市| 进贤县| 南华县| 页游| 玉屏| 罗定市| 富蕴县| 左权县| 张家川| 石泉县| 夹江县| 花垣县| 宜州市| 竹山县| 吴江市| 凌源市| 永清县| 格尔木市|