TCP/IP status explained [go]

Source: Internet
Author: User

status changes for TCP normal setup and shutdownThe establishment of a TCP connection can be simply called a three-time handshake, while a connection abort can be called a four-time handshake. Establish a connectionIn the TCP/IP protocol, the TCP protocol provides a reliable connection service with a three-time handshake to establish a connection. First handshake: When a connection is established, the client sends a SYN packet (SYN=J) to the server and enters the Syn_send state, waits for the server to confirm; second handshake: The server receives the SYN packet, must confirm the customer's SYN (ACK=J+1), and also sends a SYN packet (syn= k), the Syn+ack packet, at which time the server enters the SYN_RECV state; the third handshake: the client receives the server's Syn+ack package, sends the acknowledgement packet ack (ACK=K+1) to the server, the packet is sent, the client and the server enter the established state, Complete the three-time handshake. Complete three handshake, the client and the server start to transfer data, that is, the established state.

End Connection

TCP has a special concept called half-close, which means that TCP connections are full-duplex (can be sent and received simultaneously), so when you close the connection, you must close the transmission and send the two-direction connection. The client gives the server a fin of 1 TCP message, then the server returns a confirmation ACK message to the client, and sends a FIN message, when the client replies to the ACK message (four handshake), the connection is over.


TCP state transition diagram

This is a seemingly complex state migration diagram, because it contains two parts---the state migration of the server and the State migration of the client, if from a certain point of view this figure, it will be clear that the server and the client is not absolute, the data is sent to the client, The server is the one that accepts the data.

The state of the client can be represented by the following process:

Closed->syn_sent->established->fin_wait_1->fin_wait_2->time_wait->closed

The above process is in the normal situation of the program should have a process, from the diagram in the book can be seen, when the connection is established, when the client receives the ACK of the SYN message, the client opens the data to connect interactively. The end-of-connection is usually the client's active end, and after the client finishes the application, it needs to go through the state of Fin_wait_1,fin_wait_2, which is the four-time handshake of the end connection mentioned earlier.

The status of the server can be represented by the following process:

Closed->listen->syn received->established->close_wait->last_ack->closed

When the connection is established, the server side enters the data interaction state after the third handshake, and the close connection is after the second handshake of the connection is closed (note that it is not the fourth time). After closing, it waits for the client to give the final ACK packet in order to enter the initial state.

Other State migrations

The diagram in the book also has some other state migrations, which are summarized for both the server and the client:

1. Listen->syn_sent, for this explanation is very simple, the server sometimes to open the connection.
2. Syn_sent->syn received, the server and the client in the Syn_sent state if received SYN datagram, you need to send a SYN ACK datagram and adjust its state to the SYN received status, ready to enter the established
3. syn_sent->closed, in the case of a send timeout, returns to the CLOSED state.
4. Syn_ received->listen, if received by the RST package, will return to the LISTEN state.
5. Syn_ received->fin_wait_1, this migration is said, can not go to established state, and can jump directly to the fin_wait_1 state and wait to close.

2MSL Wait Status

The picture given in the book, there is a time_wait wait state, this state is called the 2MSL state, that is, after the time_wait2 sent the last ACK datagram, to enter the TIME_WAIT state, This state is prepared to prevent the last handshake from being delivered to the other party (note that this is not a four-time handshake, which is the fourth time that the handshake is insured). This state is to a large extent guaranteed that both sides can end normally, but the problem also comes.

Due to the 2MSL status of the socket (socket is the meaning of IP and port pairs, socket), so that the application in 2MSL time is not able to use the same socket again, for the client program is good, but for the service program, for example, httpd, it always use the same port to service, and in In 2MSL time, an error (socket is used) will occur when the httpd is started. To avoid this error, the server gives the concept of a quiet time, which means that in 2MSL time, although the server can be restarted, but the server will still wait for 2MSL time in the past before the next connection.

Fin_wait_2 status

This is known as the semi-closed state, which is the state after the client and server two handshake when the connection is closed. In this state, the application also has the ability to accept data, but it has been unable to send data, but it is also possible that the client has been in a fin_wait_2 state, and the server has been in the Wait_close state, and until the application layer decides to close the state.

RST, simultaneous turn on and off simultaneously

The RST is another way to close the connection, and the application should be able to determine the authenticity of the RST package, that is, whether the exception was aborted. While opening and closing at the same time are two special TCP states, the probability of occurrence is very small.

TCP/IP status explained [go]

Related Article

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.