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

TCP four-way handshake disconnects cohesion (illustration)

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Establishing convergence is very important, it is the premise of accurate data transmission; disconnecting convergence is very important, it allows the computer to release capital that is no longer used. If the connection cannot be disconnected normally, it will not only form a data transmission problem, but also lead to the socket cannot be closed, continue to occupy capital, if the complication is high, the pressure of the server is worrying.

Set up the connection demand three-way handshake, disconnect the connection demand four-way handshake, can be abstracted as the following dialogue:

[Shake 1] socket A: "at the end of the obligation, I wish to disconnect."

[Shake 2] socket B: "Oh, really? just a moment, please. I'll get ready."

After a little waiting...

[Shake 3] socket B: "I'm ready to disconnect."

[Shake 4] socket A: "OK, thank you for your cooperation."

The following figure shows the scenario where the client automatically disconnects the connection:

After setting up the connection, both the client and the server are in the ESTABLISED form. At this point, the client proposes a request to disconnect:

1) after misappropriating the close () function, the client sends FIN packets to the server and enters the FIN_WAIT_1 form. FIN is the abbreviation of Finish, which shows that the completion of obligations requires disconnection.

2) after receiving the data packet, the server detects that the FIN flag bit is set and knows to disconnect the connection, so it sends an "acknowledgement packet" to the client and enters the CLOSE_WAIT form.

Note: after receiving the request, the server does not immediately disconnect the connection, but first sends a "confirmation package" to the client to inform it that I know, I need to be prepared before breaking the connection.

3) the client receives the "acknowledgement packet" and lags behind the FIN_WAIT_2 form and waits for the server to send the packet again after the server is ready.

4) after waiting for less, the server is ready to end and can be disconnected, so automatically send FIN packets to the client to inform it that I am ready, disconnect it. However, it lags behind into LAST_ACK form.

5) after receiving the FIN package of the server, the client sends the ACK package to the server, informing it that you have disconnected the connection. However, it lags behind into TIME_WAIT form.

6) after receiving the ACK packet from the client, the server disconnects the connection, closes the socket, and enters the CLOSED form.

Elucidation on the form of TIME_WAIT

Why is it that the client first sends an ACK packet that lags behind the TIME_WAIT form instead of going directly into the CLOSED form of closed connection?

TCP is a connection-oriented transmission method, it is necessary to ensure that the data can accurately reach the destination machine, can not be lost or stumbled, and the collection is non-fluctuating and can destroy the data at any time, so every time Mechanical A sends a data packet to Mechanical B, it requests Mechanical B to "confirm" and return the ACK packet to inform Mechanical A that I have received it, so that Mechanical A can know that the data transmission has won. If Machine B does not return the ACK packet, Machine A will send it again until Machine B returns the ACK packet.

When the client returns the ACK package to the server for the first time, the server will not receive the FIN package due to the collection of results, and the server will send the CLOSED package again. If the client completely closes the connection, then the server will not receive the ACK package no matter what, so the client needs to wait a little to confirm that the other party has received the CLOSED package before entering the CLOSED form. So, how long do we have to wait?

Packets have a living time in the collection, beyond which the host will be discarded before it reaches the destination, and the source host will be told. This is called maximum message life time (MSL,Maximum Segment Lifetime). TIME_WAIT waits for 2MSL to enter CLOSED form. It takes MSL time for the ACK packet to arrive at the server, and MSL time for the service to transmit the FIN packet. 2MSL is the maximum time for packet reciprocation. If the FIN packet has not been received after 2MSL, it is clarified that the server has received the ACK packet.

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

Network Security

Wechat

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

12
Report