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 three handshakes and four waves

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

SYN:1 represents a request to create a connection

FIN:1 asked to close the connection, and during the four breakups, we found that FIN had sent it twice. This is because the connection to TCP is bi-directional, so FIN can only turn off one direction at a time.

ACK: represents confirmation acceptance, ACK=1, to indicate that the data has been received successfully.

Seq: sequence number, when sending a data, the data is split into multiple packets to send, the sequence number is to number each packet, so that the recipient can splice the packet again. The initial sequence number is randomly generated.

Ack: the number that the server acknowledges after receiving the data packet. Ack is seq+1.

When creating a connection

1. The client sends a syn packet (numbered seq=x) to the server, requesting to create a connection (SYN=1).

two。 After receiving the request, the server confirms the customer request (ACK=1,ack=x+1) and sends the syn packet (seq=y) to the client to tell the client to create a connection (SYN=1): I have received the request and processed it. I also want to establish a connection with you. Please confirm.

3. The client receives the SYN+ACK packet from the server and confirms the server status (ACK=1,ack=y+1). At the same time, send a syn packet (seq=x+1) to the server to tell the server: I have received your confirmation packet, you can start to communicate.

Three-way handshake is complete!

Take an example of making a phone call:

A: Hello, this is A, can you hear me

B: yes, I'm B. can you hear me?

A: yes, I hear you

Establish a connection and start chatting!

During the four breakups

1. First of all, the client should send a FIN packet (numbered seq=u) to indicate that you want to disconnect (FIN=1).

two。 After receiving the request, the server acknowledges the customer request (ACK=1,ack=u+1) and sends a data packet (seq=v) to inform the client that it needs to confirm the current server status.

3. The server completes the status confirmation (ACK=1,ack=u+1) and sends a FIN packet (seq=w) to the client requesting to close the connection (FIN=1).

4. The client receives a server-side request (ACK=1,ack=w+1) and sends a packet (seq=u+1) to the server to notify the receipt of the request and acknowledge it.

5. The client waits two seconds to confirm that the server has received the message, otherwise it will resend the confirmation message.

Four breakups are complete!

Wave four times:

A: "Hey, I'll stop."

B: "I see. Wait a minute, I haven't finished the last sentence. Balabala..."

B: "all right, I'm done, and I won't say it either."

A: "I see."

1. Why is it a three-way handshake when connecting and a four-way handshake when it is closed?

Because when the Server side receives the SYN connection request message from the client side, it can send the SYN+ACK message directly. The ACK message is used to reply, and the SYN message is used to synchronize. However, when the connection is closed, when the Server side receives the FIN message, it is likely that the SOCKET will not be closed immediately, so it can only reply an ACK message first, telling the client, "I received the FIN message you sent." Only when all the messages on my Server side have been sent, can I send FIN messages, so I can't send them together. So you need a four-step handshake.

two。 What if a connection has been established, but the client suddenly fails?

TCP also has a survival timer, obviously, if the client fails, the server can not wait forever, wasting resources. The server resets the timer every time it receives a request from the client. The time is usually set to 2 hours. If no data from the client is received in two hours, the server will send a probe message segment, and then send it every 75 minutes. If 10 probe messages are sent in a row and still do not respond, the server thinks that the client has failed and then closes the connection.

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