Why establish a TCP connection requires three-way handshake, the disconnection requires four wave

Why establish a TCP connection requires three-way handshake, the disconnection requires four wave

May 21, 2019 18:20:39  ZachLaVine  Reads 1144

1. Why three-way handshake

In order to prevent the connection request has failed segment suddenly transferred to the server, thus generating an error.

1.1 Specific examples:

Produce a "connection request has failed segment" in such a case: a first client sends a connection request message segment is not lost, but in some network nodes the residence time, resulting in delayed to a time after connection release before reaching the server. This in itself is already a failure of the segment. But the server receives this request after the failure of the connection segment, it is mistaken for a new connection request issued by the client again. So it is a confirmation message segments to client, agreed to establish a connection. Do not assume that a "three-way handshake", as long as the server a confirmation, a new connection is established. Now that no client requesting establishment of a connection, and therefore will not ignore the acknowledgment server, it will not send data to the server. But the server thought that the new transport connection has been established, and has been sent to wait for client data. In this way, a lot of resources on the server wasted. A "three-way handshake" approach can prevent this phenomenon. For example, that sort of situation, client does not send a confirmation to confirm the server. Since the server does not receive confirmation, we know that client is not required to establish a connection. "

2. Why should we break up four times

TCP protocol is a connection-oriented, reliable transport layer protocol based on the byte stream. TCP is full-duplex mode, which means that, when the host 1 issues a FIN segment, but said the host 1 has no data to send, and tells the host 2 host 1, its data have all been sent up; however, this time, the host 1 or can accept data from the host computer 2; and when the master device 2 returns an ACK segment, indicating that it already knows the host 1 does not have data transmitted, but the host 2 can still send data to the host 1; when the host 2 also when sending a FIN segment, this time that the host 2 also has no data to send, it will tell the host 1, I have no data to send, and then will pleasantly interrupt the TCP connection with each other.

A figure above 3. Why must we wait 2MSL time in TIME-WAIT state?

  • First, in order to ensure a last ACK packet sent by A can reach B. The ACK segment may be lost, thus the LAST-ACK in state B can not receive the transmitted acknowledgment FIN + ACK packet segments. This timeout retransmission B FIN + ACK segment, and A can receive the retransmitted FIN + ACK segment within 2MSL time. If A does not wait for a period of time TIME-WAIT state, but sending the ACK segment immediately after release of the connection, you can not receive FIN + ACK packet retransmitted segment B, and thus will not send confirmation again segment. Thus, B can not follow the normal steps into the CLOSED state.
  • Second, A after sending ACK segment, and then after 2MSL time, can make the present connecting all segments duration are generated disappear from the network. So it can make a new connection next segment of this old connection request does not occur.

4. a full HTTP request procedure

When we enter the address bar of your web browser: www.baidu.com then enter,, in the end what happened process overview

  • 1. www.baidu.com this URL DNS lookup to obtain the corresponding IP address
  • 2. According to this IP, find the corresponding server initiates the TCP three-way handshake
  • 3. After establishing a TCP connection sends an HTTP request
  • 4. The HTTP server responds to the request, the browser html code to obtain
  • The browser parses the html code and requests html code resources (such as js, css pictures, etc.) (first get html code to find these resources)
  • 6. browser page rendering presented to the user

4.1 Summary:

DNS -> initiates a TCP three-way handshake -> http request to initiate the establishment of the TCP connection -> Server response http request, the browser get html code -> browser parses the html code and requests html code resources (such as js, css, images, etc.) -> browser page rendering presented to the user

Guess you like

Origin blog.csdn.net/cxu123321/article/details/93653118