Several problems in the process of TCP establishing connection and releasing connection

Source: Internet
Author: User

Why is TCP using three handshake to establish a connection, if two handshakes can be used, please explain the reason?

  No. A three-time handshake is used to prevent the failure of the connection request message segment from being transmitted to the server abruptly, resulting in an error. When the client sends a connection request message segment for some reason does not reach the server in time, and the client waits for a period of time, and then re-sends the connection request to the server, and establishes the successful, the order completes the data transmission, then the first time sends the connection request message segment is called the Invalid connection request message segment.

Consider such a situation, the first time the client sends a connection request is not lost, but because the network problem caused the delay to reach the server, the server thought it was a new connection initiated by the client, so the server agreed to connect and send back the acknowledgement to the client, but at this time the client ignored, the server has been waiting for the client to send data , resulting in wasted server resources.

Why does TCP use four waves to release the connection?

When you close the connection, when you receive a FIN message notification from the other party, it simply means that no data is sent to you, but not all of your data is delivered to the other person, so you may not be able to close the socket immediately, or you might need to send some data to the other person. Send fin messages to each other to indicate that you do not have the data sent to each other, for each fin message, you need an ACK message. so we need to wave four times.

Why do I need time_wait status?

 1. Realizing the reliability of terminating TCP full-duplex connection

Assuming that the final ACK state disappears, the server will resend the final fin. Therefore, the customer must maintain the status information to allow it to re-send the final ACK, and if the status information is not maintained, it will eventually respond to RST, while the server interprets the subsection as an error. If TCP intends to perform all the necessary work to completely terminate the data flow in a connection direction, it must be able to handle any one of the four sub-sections of the connection termination sequence that is missing, i.e. the end of the active shutdown enters the time_wait state, because it may have to resend the final ack.

2. Allow old repeating sub-sections to disappear in the network

We assume that there is a TCP connection between 12.106.32.254 port 1500 and 206.168.112.219 Port 21, and after we close this connection, we establish the same IP address and TCP connection between the ports at some later time. After a connection is called the avatar of the previous connection, because their IP address and port number are the same, TCP must prevent the old repeating groupings from a connection from reproducing after the connection terminates, thus being misunderstood as belonging to the same connection avatar. To implement this function, TCP cannot start a new avatar for a connection in the TIME_WAIT state, since the duration of the time_wait state is 2MSL, which is enough to allow the grouping in one direction to survive the MSL seconds to be discarded, and the second in the other direction has the most surviving MSL seconds discarded. By implementing this rule, we can guarantee that when a TCP connection is successfully established, the old repeating groupings of the previous avatars from that connection have disappeared in the network.

  

Resources:

1.http://coolshell.cn/articles/11564.html

2. "Benevolent Programmer"

  

Several problems in the process of TCP establishing connection and releasing connection

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.