TCP Connection Status Detailed

Source: Internet
Author: User
Tags ack


The process of a TCP connection undergoes a series of state changes, including:

Listen,syn_sent,syn-received,established,fin-wait-1,fin-wait-2,close-wait,closing,last-ack,time-wait,closed. Where closed is a fictitious state, because the closed TCP connection TCB (transmission Control Block) has been released, so this TCP connection is no longer present. A brief description of each state: LISTEN: Listens for and waits for a TCP connection request to the end syn-sent: After the SYN connection request is sent, wait for the peer to reply to the SYN request syn-received: After receiving the SYN request from the peer and replying to the SYN request, ACK message waiting for the peer response to the SYN request established: On behalf of the connection established, the two parties in this state for TCP data interaction fin-wait-1: After sending fin close connection request, wait for the other side to respond to the fin ACK message or to the end of the fin close request Fin-wait-2: Waiting for the other fin to close the request close-wait: Wait for the local user (process) to send a fin close request to the peer CLOSING: when both sides send a fin close request, the CLOSING state is entered. Response ACK message waiting to send fin messages to the end Last-ack: After receiving the end fin request, reply ACK and fin and wait for the other side to reply to the response ACK message of fin, at this time enter this state time-wait: This state is to ensure that the peer receives the ACK response of the fin request, The default is to wait twice times the MSL time (Msl:maximum Segment Lifetime, which is the maximum lifetime of the message, and messages that exceed this time are discarded)

For the change relationship between the above states, you can refer to the TCP connection status change graph in RFC-793:

Note:

The contents of the "---------" in the figure represent conditions for a state transition (for example, snd syn,ack means sending SYN and ACK messages, RCV fin means receiving fin messages, etc.)

The "+-------+" frame in the figure is the status of each TCP connection

The arrows "-------->" in the figure indicate the order of transitions between states (there are also various polyline arrows)

The process of the TCP three handshake and the state switching process description:

TCP A TCP B

1. CLOSED LISTEN

2. Syn-sent-<SEQ=100><FLAGS=SYN>-syn-received

3. Established <--<SEQ=300><ACK=101><FLAGS=SYN,ACK> <--syn-received

4. Established-<SEQ=101><ACK=301><FLAGS=ACK>-established

5. Established-<SEQ=101><ACK=301><FLAGS=ACK><DATA>-established

Procedure Description: B as the server side in the listen state, listen to the external TCP connection a Send SYN connection request to B, enter the Syn-sent state, B received the connection request, enter syn-received State B reply Syn,ack to A, A after receiving the established State a reply ACK to b,b received also entered established state both sides began to exchange data

Looking at a more complex handshake process, both parties initiate a TCP connection to each other at the same time in the closed state:

TCP A TCP B

1. CLOSED CLOSED

2. Syn-sent-<SEQ=100><FLAGS=SYN> ...

3. syn-received <--<SEQ=300><FLAGS=SYN> <--syn-sent

4 ... <SEQ=100><FLAGS=SYN>-syn-received

5. syn-received-<SEQ=100><ACK=301><FLAGS=SYN,ACK> ...

6. Established <--<SEQ=300><ACK=101><FLAGS=SYN,ACK> <--syn-received

7 ... <SEQ=101><ACK=301><FLAGS=ACK>-established

Procedure Description: A and B are in closed state A to B send a SYN connection request, a into the syn-sent state due to network delay, step 2 in a sent SYN request has not reached B, at this time B sends a SYN request to a, into the syn-sent State, A after receiving the 2nd step into the syn-received state, the SYN request from a has just arrived B,b received, enter syn-received status a reply syn,ack to B's SYN request B reply Syn,ack to a, because

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.