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-way handshake and four waving

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

TCP's three handshakes and four waves: questions often asked by interviewers during an interview

In the Internet, how to make the hosts of different network segments communicate with each other needs to use the TCP protocol.

TCP, which provides connection-oriented services, must establish a connection before transmitting data, and release the connection after the data transfer is completed. TCP is a reliable transportation service that uses a three-way handshake to establish a connection.

First of all, introduce the message format of TCP.

The sender of the serial number is numbered for each byte, so it is convenient for the receiver to reorganize correctly.

The confirmation number is used to confirm the information of the sender.

The window size is used to indicate the number of locally acceptable segments.

Marker bit

URG emergency pointer position 1 is turned on and off.

Submit it directly to the other party without caching.

PSH Quick accept and pass to Application layer 1 enable 0 close

You need to go through caching, wait for a batch of message segments to arrive, and send them directly to the application layer.

Request tag for establishing a connection with SYN synchronous sequence number bits

Request flag for FIN disconnection

ACK confirm sequence number bit

RST reconnect

Three-way handshake

First handshake

The client wants to establish a connection with the server, so it sends a SYN to the server and waits for the server to confirm

The second handshake

After receiving the request message, the TCP server first confirms the SYN packet and sends out the SYN+ACK packet if it agrees to connect.

The third handshake

After receiving the SYN+ACK packet from the server, the client also needs to send the acknowledgement packet ACK to the server. After this packet is sent, the two sides can start to communicate and complete the three-way handshake.

Waving four times

Because the TCP connection is full-duplex, each direction must be closed separately. This principle is that when a party completes its data transmission task, it can send a FIN to terminate the connection in this direction. Receiving a FIN simply means that there is no data flow in this direction, and an TCP connection can still send data after receiving a FIN. The first party to perform the shutdown will perform an active shutdown, while the other party will perform a passive shutdown.

Wave for the first time

The server sends the TCP message segment of FIN and ACK location 1 to the client.

The second wave.

The client returns the TCP message segment of ACK location 1 to the server.

Wave for the third time

The client sends the TCP message segment of location 1 of FIN and ACK to the server.

In the process of disconnecting TCP, there is a semi-closed concept. A party to the TCP (usually the client) can terminate sending data, but can still accept the data, which is called a semi-shutdown.

Why do you shake hands three times when establishing a connection and wave four times when you disconnect?

When the server closes the connection, when it receives the FIN message from the other party, it means that the other party will no longer send data, but it can still receive the data, and it may not send all the data to the other party, so after sending the data to the other party, it will send the FIN message to the other party to indicate that it agrees to close the connection now. Therefore, ACK and FIN are generally sent separately, resulting in one more time.

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