11 state transitions of TCP connections

Source: Internet
Author: User
Tags ack

Transferred from: http://blog.csdn.net/engrossment/article/details/8104482

http://blog.csdn.net/xiaofei0859/article/details/6044694


11 state transitions of TCP connections

1, the first picture:



2, all 11 kinds of states

2.1, the Client Exclusive: (1) syn_sent (2) fin_wait1 (3) fin_wait2 (4) CLOSING (5) time_wait.

2.2, the server unique: (1) LISTEN (2) SYN_RCVD (3) close_wait (4) Last_ack.

2.3, the total: (1) CLOSED (2) established.


3. State change

3.1, the state changes when establishing the connection

Initially, the server and client state are closed before the connection is established. The server starts listening after the socket is created and becomes listen state. The client requests a connection, sends a SYN message to the server, and the client's status changes to Syn_sent. When the server receives a message from the client, it sends an ACK and a SYN message to the client, and the server state changes to SYN_RCVD. The client then receives an ACK, SYN, sends an ACK to the server, the client state becomes established, and the server receives an ACK from the client and becomes established. At this point, 3 times the handshake is complete and the connection is established.

3.2, the state changes when disconnected

Because TCP connections are full-duplex, disconnecting is a little more hassle than establishing a connection. The client sends a FIN message to the server, requests a disconnection, and its status changes to Fin_wait1. After the server receives the fin, an ACK occurs to the client, and the server state changes to close_wait. When the client receives an ACK, it enters the fin_wait2 state. The connection is now half broken. If the server still has data to send to the client, it will continue to be sent. The FIN message is sent when the server enters the Last_ack state until it is finished. After the client receives the fin from the server, it immediately sends an ACK to the server, when the client enters the TIME_WAIT state and then enters the closed state after a long period of 2MSL. The server receives an ACK from the client and enters the closed state.

At this point, there is another state that is not mentioned: closing state. The closing status indicates that the client has fin, but receives no ACK from the server, but receives the fin from the server. This happens when the server sends an ACK drop, because the network transmission can sometimes be unexpected.

What is 2MSL

MSL is maximum Segment lifetime English abbreviation, Chinese can be translated as "maximum message survival time", he is any message on the network for the longest time, more than this time the message will be discarded. Because the TCP message (segment) is the data portion of the IP datagram (datagram), refer to the "data in each layer of the network," the article, and the IP header has a TTL field, the TTL is the abbreviation of time to live, Chinese can be translated as "lifetime", This time-to-live is the initial value set by the source host, but not the time it was saved, but rather the maximum number of routes that an IP datagram can pass, with the value minus 1 for each router that passes through one, and when this value is 0, the datagram is discarded, sending an ICMP message to the source host. The MSL is specified in RFC 793 for 2 minutes, and the actual application is 30 seconds, 1 minutes and 2 minutes.

2MSL that is twice times the time_wait state of the msl,tcp is also known as the 2MSL wait state, when one end of TCP initiates an active shutdown, after the last ACK packet is sent, that is, after the 3rd handshake is completed, the fourth handshake after the ACK packet has entered the TIME_WAIT state, Must stay two times in this state of the MSL time, waiting for 2MSL time the main purpose is to be afraid of the last ACK package the other party confiscated, then the other party after the timeout will be re-post the third handshake fin bag, active close to the re-issued Fin packet can be sent an ACK reply packet. Ports on both ends cannot be used in the TIME_WAIT state, and will not continue to work until the end of 2MSL time. Any late message segments are discarded when the connection is in the 2MSL wait phase. In practice, however, you can use this port by setting the SO_REUSEADDR option to not have to wait until the end of 2MSL time.

The TTL is related to the MSL but is not a simple equal relationship, and the MSL is greater than or equal to the TTL.


I draw the picture myself:




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.