The TCP finite state machine

The picture shows the TCP state transition, meaning that each state is as follows:
  1. CLOSE: an initial state the state machine;
  2. LISTEN: passive open, server-side state to LISTEN (monitor);
    1. Passive open: one end connected applications inform the operating system, want to establish an incoming connection. This time the operating system to establish a connection to this end;
    2. Active connection: An application by an active open request to tell the operating system to establish a connection;
  3. SYN_RCVD: the server received SYN, the status of SYN, transmits SYN ACK;
  4. SYN_SENT: the application sends a SYN, the SYN_SENT state;
  5. ESTABLISHED: After SYN_RCVD received ACK, the state becomes ESTABLISHED; SYN_SENT after receiving the SYN ACK, transmits ACK, changes the ESTABLISHED state;
  6. CLOSE_WAIT: the server after receiving the FIN, transmitting the ACK, the state becomes the CLOSE_WAIT; At this time, if the server has more data to transmit, then the transmission until the data transmission is completed, then the server sends the FIN, the state becomes LAST_ACK;
  7. FIN_WAIT_1: Application sends the FIN, the TCP connection is disconnected ready state from ESTABLISHED-> FIN_WAIT_1;
  8. FIN_WAIT_2: application server end receives only the ACK, the FIN is not received, that the server has more data to transmit, then the time for the semi-connected;
  9. TIME_WAIT: There are two ways to enter the state. TIME_WAIT is to achieve full-duplex connection reliability of closing of a TCP, it could be used to retransmit lost ACK packet; need to continue the MSL 2 (maximum packet lifetime) time; assume the application port into the TIME_WAIT, 2 after MSL did not receive FIN, ACK illustrate the application last issue has been received; otherwise, you will receive ACK packet again within two MSL.
    1. FIN_WIAT_1 state entry: Your application port receives the FIN ACK (ACK not received only as image FIN_WAIT_2, description has been sent data) and transmits the ACK server;
    2. FIN_WAIT_2 state to: Your application port receives the FIN, and then sends an ACK to the server;
 
The client application state transition route:
  CLOSED->SYN_SENT->ESTABLISHED->FIN_WAIT_1->FIN_WAIT_2->TIME_WAIT->CLOSED
The above process should be some process, you can see from the image above normal procedure under the circumstances, when the connection is established, When the client receives SYN packet ACK, the client opens the data interactively connected. The end of the connection is usually the client end of the initiative, after the end of the client application, you need experience FIN_WAIT_1, FIN_WAIT_2 and other states.
 
Status of the server migration routes:
  CLOSED->LISTEN->SYN收到->ESTABLISHED->CLOSE_WAIT->LAST_ACK->CLOSED
When the connection is established, the server is after the third handshake before entering the data exchange state, and the connection is closed after closing the connection of the second handshake (Note that not fourth). After closing to wait while the client is given the final ACK packet to enter the initial state.
 
Other State Migration:
  There are some other figure above state transition, which summarizes the state transition for both the server and client are as follows:
    • LISTEN-> SYN_SENT, for this explanation is very simple, sometimes have to open a connection to the server thing.  
    • SYN_SENT-> SYN_RCVD, server and client If you receive SYN packets, you will need to send a SYN ACK packets in SYN_SENT state and to adjust their status to SYN_RCVD state, ready to enter the ESTABLISHED
    • SYN_SENT-> CLOSED, in the case of transmission timeout, returns to the CLOSED state.
    • SYN_RCVD-> LISTEN, if subject to RST packet, returns to the LISTEN state.
    • SYN_RCVD-> FIN_WAIT_1, this migration is that you can do to ESTABLISHED state, and can jump directly to FIN_WAIT_1 state and wait for the close.
 

 

Guess you like

Origin www.cnblogs.com/Jummyer/p/11068068.html