TCP protocol-http protocol-time-wait-close-wait must know

Source: Internet
Author: User

Preface:

During the four-time TCP wave , who voluntarily disconnects, who has time_wait, passive disconnects one side will have close_wait

    • Time_wait: Keep the end share population with 2mls~4min, avoid the other side still have some TCP chip sends to this port, the new chain accepts the influence. Disadvantages of Time_wait: taking up memory
    • Close_wait: The passive closing party receives the fin signal immediately after the reply ACK means to receive the fin signal, while entering the close_wait state, waiting for the data to complete the transmission completed, close_wait status end, send fin signal. That is, the purpose of the close_wait is to wait for data that is not transferred to complete.
 HTTP 1.0 and 1.1 

http1.0 default is a short connection, client-side initiative, server-side service is complete, the connection is closed, the client side also to determine the data sent over. Therefore http1.0 times, the service side is easy to have more time_wait.

    • if the HTTP 1.0 protocol, the client wants to use a long connection, you need to set the connection:keep-alive in the header  

http1.1 default is long connection

    • If the client does not want to use a long connection, you need to set the Connection:close in the header
    • If the server does not want to use long connections, you also need to set the Connection:close in reponse
The keep-alive parameter in the HTTP header is used to set the number of seconds the client wants the server to remain connected for a long connection problem

Keep-alive mode problems: The server does not close the connection at this time, the client how to know whether the message content is sent (Bfe once because the http1.0 did not actively close the connection, resulting in some old PHP socket HTTP packet timed out due to waiting for the server to close the connection to determine that the message was sent

Keep-alive mode, in two ways

    • Server Reqponse set content-length parameter: tells the content size, the client receives the specified content length, can close the connection. This is also the case when the client sends a post, and if the value of Content-length is greater than the actual occurrence, it will time out, less than the server will respond 400. This mode is defective, the dynamic page server does not know the content size, only after the content is fully prepared to know, if it is sent at this time, the efficiency is too low.
    • transfer-encoding:chunked Mode: This mode is simply said to be a special response to the data format, which will contain the body end of the flag. When the client receives this flag, it knows that the data is sent and can assemble and decrypt the data.
Content-length,transfer-encoding,content-encoding

    • transfer-encoding: Transmission code, for the transmission process, the transmission of the decoding to get the object. It is used to ensure the successful transmission of data safely in the network transmission country. in http1.1, if there is a transfer-encoding, it must be chunked, at this time cannot have the Content-lengh parameter, even if there is also ignored. Transfer-encoding conflict, because transfer-encoding will change the actual data length by changing the way the data is organized by additional processing, if the client still handles the original content-length. , the complete data is not received.
    • Content-encoding: Content encoding and accept-encoding correspondence. Gzip, for example, has a good compression effect on text.

Two very good articles attached

1. Introduction to http:https://www.byvoid.com/zhs/blog/http-keep-alive-header

2.content-length:http://www.tuicool.com/articles/FJ7rye

3.http Protocol Official document: Http://greenbytes.de/tech/webdav/rfc7230.html#header.content-length

TCP protocol-http protocol-time-wait-close-wait must know

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.