Http connection and the difference in the length of the long link websocket (rpm)

Transfer from https://www.cnblogs.com/Catherine001/p/8359153.html

First, what is the http protocol

HTTP is an application layer protocol, stateless, the port number is 80. The main versions 1.0 / 1.1 / 2.0.
 
  • HTTP / 1. * a request - response, a connection is established, run off;
  • HTTP / 1.1 serializer single thread, can be transmitted simultaneously on the same link a plurality of requests tcp, but only in response is in order, only one request is completed, in response to the next. Once task processing timeout, a subsequent task can be blocked (head of line blocking);
  • HTTP / 2 in parallel. A serious time-consuming task, the task will not affect the normal execution
 
Second, what is websocket
 
Websocket is a protocol specification html5 proposed to solve the client and server communicate in real time. Essentially based on tcp, first created after the TCP handshake for exchanging data connection initiated a special http request through HTTP / HTTPS protocol.
 
WebSocket advantage: the browser and the server only needs to do a handshake action, after the connection is established, the two sides can at any time, push each other information. Meanwhile, the header information exchanged between the client and the server is small.
 
Third, what is the long connection, short connection
 
  • Short connection:
Connection -> transmit data -> close the connection
HTTP is stateless, browsers and HTTP server every once operational, will establish a connection, but the task will end disconnected.
It can be said: short connection refers to completely receiving the data transmitted immediately after SOCKET connection is disconnected.
 
  • Long connection,
Connection -> transmit data -> remain connected -> transmit data ->. . . -> close the connection.
After establishing a long connection refers to the SOCKET connection regardless of whether the connection is maintained, but less secure.
 
 
Fourth, the long connection of the difference between http and websocket
 
HTTP1.1 by using Connection: keep-alive for a long connection, HTTP 1.1 persistent connections default. A TCP connection in a plurality of HTTP requests can be completed, but still want to send the request header for each individual, Keep-Alive not permanently remain connected, it has a hold time, may be provided in different server software (e.g., Apache) in given this time. Such a long connection is a "pseudo-links"
websocket long connections, is a true full-duplex. Tcp connection after the first long link is established, subsequent data may both be transmitted, no transmission request header.
 
keep-alive two sides did not really establish a positive connection session, the server can be turned off at any time after the request is completed. WebSocket itself was subject to a positive true, long-duplex connection, both sides must maintain a live connection status.
 
 
 
Reference links:
And a socket connector 1.http long and short connecting distinction  https://www.jianshu.com/p/b68d2b26f5f4

Guess you like

Origin www.cnblogs.com/ffaiss/p/11357055.html
Recommended