Say goodbye gracefully - TCP protocol waves four times

Say goodbye gracefully - TCP protocol waves four times

Say goodbye gracefully

Leaving without saying goodbye always catches people off guard. When we have to end a pleasant chat and leave a city that is hard to leave, what will you do?

Of course, you have to learn to say goodbye gracefully.

The article "Say Hello Politely - TCP Protocol Three-Way Handshake" has already introduced how the TCP protocol establishes a connection. After the connection is established and the data transmission is completed, how can we close the connection gracefully?

Never forget - TCP's four waves

First wave

When the client is ready to close the connection, it sends a FIN=1 data packet to the server and enters the FIN_WAIT_1 state.

Second wave

After receiving the FIN=1 packet from the client, the server will respond with an ACK packet to the client and enter the state of preparing to close the connection. The server will then start preparing to stop data transmission.

After the client receives the ACK data packet from the server, it enters the FIN_WAIT_2 state. At this time, there may still be data transmission, and it needs to wait for the server to actually stop data transmission before entering the closed state.

The third wave

After the server completes the data transmission, it sends a FIN packet to the client and enters the LASK_ACK state, indicating that the server has entered the connection closing state.

The fourth wave

After the client receives the FIN packet, it can confirm that data transmission has completely stopped, enters the TIME_WAIT state, and responds to the server with an ACK packet. After waiting for 2MSL (Maximum Segment Lifetime), the connection is actually closed and enters the CLOSE state.

After receiving the ACK data packet, the server disconnects and enters the CLOSE state.

Retry and Fault Tolerance

After a FIN packet is sent, any packet that does not receive an ACK response for a long time will trigger a timeout retransmission.

Why does the client not close the connection immediately after receiving the FIN command, but waits for 2MSL time before closing it?

Assume that the client is not in the TIME_WAIT state, but closes the connection. If the client immediately re-establishes the connection, after the connection is successfully established, it receives the data packet of the previous closed connection and responds to the server with an ACK data packet, which will cause data confusion on the server.

Summarize

When the TCP protocol closes a connection, since data transmission may be in progress, both the client and the server will first enter the process of waiting to close the connection.

When the client or server sends a FIN data packet and does not receive an ACK response packet within a certain period of time, it will retry.

After the client finally receives the FIN data packet from the server, it will first enter the TIME_WAIT state and wait for 2MSL (maximum message life cycle) to prevent the occurrence of message transmission disorder caused by network delays, message transmission timeouts and other issues.

<<:  Say hello politely - TCP protocol three-way handshake

>>:  6G Internet of Things: From the Internet of Everything to the Intelligent Internet of Everything, opening up smart life, smart production and smart society

Recommend

15 Best Practices for Fiber Optic Cable Installation in Data Centers

CABLExpress recently released its latest Fiber Op...

[Closed] NextArray: $1.99/month KVM-1GB/10GB/1TB/Portland Data Center

[Closed] NextArray has added three new US nodes th...

HostVDS: $0.99/month - 1GB/10GB/50M-200M bandwidth/Russia & Dallas data centers

HostVDS has been established for some time. The m...

2018 Top Ten Internet Trends Prediction: 5G Becomes the Focus

Whether it is the turbulent forty years in Wu Xia...

How to prevent 5G from creating a new digital divide

There is no doubt that more pervasive 5G technolo...

5G and manufacturing advantages: optimism tempered

5G-enabled factories will have the ability to mai...

What are the five skills required for data center management?

Today, IT managers must be prepared for the vario...

What is 6G and the future of wireless?

While 5G is still being rolled out to replace the...

An article brings you Lwip network port interface netif

[[395199]] 01Introduction to Network Interface In...