Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction of TCP's three-way handshake and four waves and 11 states

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "TCP three-way handshake and four waves and the introduction of 11 states". In daily operation, I believe many people have doubts about the introduction of TCP three-way handshake and four waves as well as 11 states. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "TCP three-way handshake and four waves as well as the introduction of 11 states"! Next, please follow the editor to study!

1. Three-way handshake

Setting concept: according to the header field of TCP, there are three important identifiers ACK, SYN, and FIN

ACK: indicates a validation field

SYN: set the number of digits to 1, indicating the establishment of a TCP connection

FIN: set the number of digits to 1, which means disconnecting the TCP connection

The process of the three-way handshake explains:

1. The client sends a request message for establishing a TCP connection, in which the message contains the seq sequence number, which is randomly generated by the sender, and the SYN field in the message is set to 1, indicating that a TCP connection needs to be established. (SYN=1,seq=x,x is a randomly generated value)

2. The server replies to the TCP connection request message sent by the client, which contains the seq sequence number, which is randomly generated by the replying end, and the SYN is set to 1, and the ACK field is generated. The ACK field value is added to the serial number seq sent by the client to reply, so that when the client receives the message, it knows that its TCP establishment request has been verified. (SYN=1,ACK=x+1,seq=y,y is randomly generated.) ack plus 1 here can be understood as confirming who to establish a connection with.

3. After receiving the TCP establishment verification request sent by the server, the client will add 1 to its serial number, and reply to the ACK verification request again, adding 1 to the seq sent by the server. (SYN=1,ACK=y+1,seq=x+1) 2 or 4 waving

The process of waving four times:

1. The client sends a message requesting disconnection from TCP, in which the message contains the seq sequence number, which is randomly generated by the sender, and the FIN field in the message is set to 1, indicating that the TCP connection needs to be disconnected. (FIN=1,seq=x,x is randomly generated by the client)

2. The server will reply to the TCP disconnect request message sent by the client, which contains the seq serial number, which is randomly generated by the replying end, and will generate an ACK field. The ACK field value is added to the seq serial number sent by the client to reply, so that when the client receives the message, it knows that its TCP disconnection request has been verified. (FIN=1,ACK=x+1,seq=y,y is randomly generated by the server)

3. After replying to the client's TCP disconnection request, the server will not disconnect the TCP connection immediately. The server will first ensure whether all the data transferred to A has been transferred before the disconnection. Once the data transmission is confirmed, the FIN field of the reply message will be set to 1 and a random seq sequence number will be generated. (FIN=1,ACK=x+1,seq=z,z is randomly generated by the server)

4. After receiving the TCP disconnect request from the server, the client will reply to the disconnect request from the server, including the randomly generated seq field and ACK field. The ACK field will add 1 to the seq of the TCP disconnect request from the server, thus completing the verification reply of the server request. (FIN=1,ACK=z+1,seq=h,h is randomly generated for the client)

So far, the 4 waves of TCP disconnection have been completed in 3 or 11 states.

1. At the beginning, both the server and the client have the status of CLOSED before establishing the connection.

2. After the socket is created, the server starts listening and becomes LISTEN.

3. The client requests to establish a connection and sends a SYN message to the server. The status of the client changes to SYN_SENT.

4. After receiving the message from the client, the server sends ACK and SYN messages to the client, and the status of the server becomes SYN_RCVD.

5. Then, when the client receives ACK and SYN, it sends ACK to the server, and the client status changes to ESTABLISHED

6. After receiving the ACK from the client, the server becomes ESTABLISHED. At this point, 3 handshakes are completed and the connection is established!

Because the TCP connection is full-duplex, disconnecting the connection can be a little more troublesome than establishing a connection.

1. The client first sends a FIN message to the server, requesting to disconnect, and its status changes to FIN_WAIT1.

2. After receiving the FIN, the server sends the ACK to the client, and the status of the server surrounds the CLOSE_WAIT

3. After receiving the ACK, the client enters the FIN_WAIT2 state, and the connection is halfway disconnected. If the server still has data to send to the client, it will continue to send

4. When the data is sent, the FIN message will be sent, and the server will enter the LAST_ACK state.

5. After the client receives the FIN from the server, it immediately sends the ACK to the server, and the client enters the TIME_WAIT state.

6. Enter the CLOSED state after 2MSL for a long time. The server enters the CLOSED state when it receives the ACK from the client.

At this point, there is another state that has not come out: the CLOSING status.

The CLOSING status indicates:

The client sends a FIN, but does not receive the server's ACK, but receives the server's FIN, which occurs when the ACK sent by the server is lost, because there are sometimes accidents in the network transmission. LISTEN: waiting for connection requests from any remote TCP and port. SYN_SENT: wait for a matching connection request after sending a connection request. SYN_RECEIVED: wait for the connection request to be confirmed after sending the connection request and receiving the matching connection request. ESTABLISHED: indicates an open connection where received data can be delivered to the user. The normal state of the data transfer phase of the connection. FIN_WAIT_1: wait for a connection termination request from the remote TCP, or wait for the confirmation of a previously sent connection termination request. FIN_WAIT_2: waits for a connection termination request from the remote TCP. CLOSE_WAIT: waits for a connection termination request from a local user. CLOSING: waits for confirmation of the connection termination request of the remote TCP. LAST_ACK: waits for acknowledgement of a connection termination request previously sent to the remote TCP (including acknowledgement of its byte connection termination request) TIME_WAIT: waits for enough time to pass to ensure that the remote TCP receives an acknowledgement of its connection termination request. There are two reasons why TIME_WAIT exists: 1. Reliable termination of tcp full-duplex connection; 2. Allow the old repetitive sections to disappear in the network. CLOSED: not in the connected state (this is to facilitate the description of the hypothetical state, which actually does not exist). This is the end of the study on "TCP three-way handshake and four waves and introduction to 11 states". I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report