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

What is the process and reason of four waving in TCP/IP agreement

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

Share

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

The purpose of this article is to share with you the process and reasons of the four waves in the TCP/IP agreement. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Without saying much, let's take a look at it.

What do you do with four waves?

The connection of the TCP is full-duplex, so the removal of the connection requires the removal of the two channels separately, and all the four waves do is to dismantle the two channels and release resources.

TCP provides one end of the connection with the ability to receive data from the other end of the connection after it ends its transmission, also known as a half-close.

TCP/IP detailed unpacking Volume I

Here Client is used as the active initiator and Server as the passive shutdown end.

In the first step, Client initiates a Req to Server, which contains the Seq sequence number N of the FIN identification bit = 1MagneCLient, which represents the current sequence number of the current Client on the connection.

In the second step, after receiving the Req message containing FIN, the server will immediately reply the ACK message to the server after verification. The message contains the ACK flag bit 1, and the Seq number is the Seq number + 1 of the request message of FIN. At this time, the Sever will also actively send an end logo to the application layer program above the Server, which can decide whether to finish immediately or wait until the data in the connection on the server has been processed, and then send a FIN message to Client to close the other half of the connection.

Third, after the server has processed the Pending resident data on the connection, the application will close the connection. Client initiates the Req message of FIN to the client. Inside the message is the Terminator identifier bit of FIN=1 and the Seq sequence number on the server side.

In the fourth step, after receiving the corresponding FIN message, the client will actively notify the application layer program that the connection needs to be closed now. The Client then replies to the Server with an ACK message to disconnect the channel in the other direction, which contains the identification bit of the ACK=1 and the Seq+1 brought by FIN's REQ.

Why do you need four waves?

Because TCP is a full-duplex protocol, each channel must be dismantled separately. The purpose of 4 waves is to terminate data transmission and reclaim resources. At this time, there is no relationship between the sequence numbers of the two endpoints in both directions. You must wait until there is no data transmission in either direction before removing the virtual link. It is not as simple as initialization. When you find the SYN flag, initialize a sequence number and confirm the SYN sequence number. Therefore, data transmission in that direction must be terminated separately in one direction.

What happens if you wave three times? For three times, after receiving the FIN message, the passive shutdown side needs to reply to the ACK and server FIN messages at the same time. If the Server side does not have a Pending message to process on the connection, then it is OK. If the Server side needs to wait a while before closing the connection in the other direction, then such three waves will not meet the conditions.

A state transition with four waves?

Client side:

ESTABLISHED--- sends FIN to Server-- > FIN_WAIT_1--- receives the corresponding ACK-- of the FIN on the server > FIN_WAIT_2--- receives the FIN message sent by the server-- > FIIN_WAIT--2MSL will enter-- > CLOSED

Server side:

ESTABLISHED--- receives client FIN- > CLOSED_WAIT-- Server application shuts down sending FIN-- > LAST_ACK--- receives Client's ACK response to FIN-> FIIN_WAIT---- > CLOSED

Tcp/ip detailed unpacking Volume I

The corresponding relationship between the four waves and the Scoket function is as follows:

The picture is from the Internet. If there is any infringement, please let me know and delete it in time.

What happens if you fail to wave four times?

Among the four waves, the most classic scene is the time processing of 2MSL when Client is behind TIME_WAIT. Note: MSL is the maximum lifetime of a TCP message, and it is the longest time spent in the network before any message segment is discarded. )

The purpose of setting 2MSL is to handle the time when Client can send the last FIN when the Server side retransmits the last ACK.

During this period of time, it is best not to reuse the port of this TCP, whether on Client or Server, otherwise, the newly established connection based on this port may be incorrectly shut down, as shown below:

The last FIN,Client that step1:Server sent to Client received and sent ACK to Server, but Server did not receive the ACK. Step2: so CLient reuses the Port number, so a new connection is created, which is assumed to be newConnection. In the process, step3:Server has sent a retransmitted FIN to Client,Client and the newly created newConnection will be turned off again.

The above is the process and reason of the four waves in the TCP/IP agreement. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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