Home > Common Problem > What does websocket mean?

What does websocket mean?

hzc
Release: 2020-06-24 11:13:23
Original
6302 people have browsed it

What does websocket mean?

WebSocket is a protocol for full-duplex communication over a single TCP connection. The WebSocket communication protocol was designated as standard RFC 6455 by the IETF in 2011, and was supplemented by RFC7936. WebSocket API has also been designated as a standard by W3C.

WebSocket makes data exchange between the client and the server simpler, allowing the server to actively push data to the client. In the WebSocket API, the browser and the server only need to complete a handshake, and a persistent connection can be created directly between the two for bidirectional data transmission.

Advantages

  • Less control overhead. When data is exchanged between the server and client after a connection is created, the packet headers used for protocol control are relatively small. Without extensions, for server-to-client content, the header size is only 2 to 10 bytes (related to the packet length); for client-to-server content, additional headers need to be added. 4-byte mask. Compared with HTTP requests that carry complete headers every time, this overhead is significantly reduced.

  • Stronger real-time performance. Since the protocol is full-duplex, the server can proactively send data to the client at any time. Compared with HTTP requests, which need to wait for the client to initiate a request before the server can respond, the delay is significantly less; even compared with similar long polling methods such as Comet, it can deliver data more times in a short period of time.

  • Stay connected. Unlike HTTP, Websocket needs to create a connection first, which makes it a stateful protocol, and some state information can be omitted during subsequent communications. HTTP requests may need to carry status information (such as identity authentication, etc.) in each request.

  • Better binary support. Websocket defines binary frames, which can handle binary content more easily than HTTP.

  • can support extensions. Websocket defines extensions, and users can extend the protocol and implement some customized sub-protocols. For example, some browsers support compression, etc.

  • Better compression effect. Compared with HTTP compression, Websocket, with appropriate extension support, can inherit the context of previous content and significantly improve the compression rate when transmitting similar data.

Handshake Protocol

  • WebSocket is an independent protocol created on top of TCP.

  • Websocket performs a handshake through the 101 status code of the HTTP/1.1 protocol.

  • In order to create a Websocket connection, a request needs to be made through the browser, and then the server responds. This process is often called "handshaking".

The above is the detailed content of What does websocket mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template