是什么
WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection.
websocket,和http一样,是一种应用层协议
它的 uri pattern 为 ws://xxx
![](https://img.haomeiwen.com/i19699478/65e2f49c3c033ba7.png)
它的特点是:一旦handshake建立连接后,client可以向server发消息,server也可以主动向client发消息(here is so called full-duplex).
websocket搭建了双向的消息通道,server掌握了推送信息的主动权,而不必像http那样等待client请求后才被动响应。这是它最大的特点
优势
The WebSocket protocol enables interaction between a web browser (or other client application) and a web server with lower overhead than half-duplex alternatives such as HTTP polling, facilitating real-time data transfer from and to the server.
This is made possible by providing a standardized way for the server to send content to the client without being first requested by the client, and allowing messages to be passed back and forth while keeping the connection open
应用
http://websocketd.com/ 快速启动一个websocket的server end service
https://github.com/joewalnes/web-vmstats 将机器上的vmstats命令输出以websocket的服务对外推送
网友评论