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

The third of the Fifteen principles-- the three-way handshake and four-time disconnection principle of TCP/IP

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

Share

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

The meaning of important flag bits:

ACK: indicates confirmation. The acknowledgment field of the TCP message is valid only when the ACK flag bit is 1.

SYN: indicates synchronization, which is used to synchronize the sequence number when the connection is established. When SYN=1 and ACK=0, it indicates that this is a connection request message. If the other party agrees to establish a connection, in the response message, SYN=1,ACK=1. Therefore, when the synchronization bit SYN is set to 1, it indicates that this is a connection request message or a connection accept response message.

FIN: used to release a connection. When the FIN bit is 1, the sender data of this message segment has been sent and the connection is required to be released.

1. TCP/IP 's three-way handshake

First handshake: first, the sending host initiates a synchronous (SYN) request SYN (X) to establish a connection to the receiving host, enters the SYN_SENT state, and waits for confirmation from the receiving host.

Second handshake: after receiving this request, if the receiver agrees to establish a connection, it sends an acknowledgement ACK, confirming that the serial number is the received serial number plus 1, and the SYN in the message should also be set to 1, that is, it replies to a synchronous / acknowledgement (SYN/ACK) reply message to the sender host and enters the SYN_RECVD state.

The third handshake: after receiving this reply message, the sender host sends an ACK message to the receiver, and then both the sender and receiver enter the ESTABLISHED state and complete the three-way handshake. at this point, the TCP connection is established successfully, and the sender and receiver can begin to transmit data.

The three-way handshake process for TCP to establish a connection is shown in the figure:

2. Four disconnections of TCP/IP

When the application process ends the data transfer, the established connection is released. The TCP connection is bi-directional and must be closed separately in each direction. The first party that closes performs the active closure, while the other party performs the passive closure.

1. When the data transmission of the client is finished, you can actively send the message of FIN setting 1 to the server (the client shuts down actively) to shut down the data transmission from the client to the server, wait for the ACK confirmation reply from the server, and enter the FIN_WAIT1 state at the same time.

2. After receiving the message of FIN setting 1, the server enters a passive shutdown, replies to an ACK confirmation message, and enters the CLOSE_WAIT state; after receiving the ACK confirmation message, the client enters the FIN_WAIT2 state.

3. At this point, the semi-closure of the TCP connection is completed, that is, the data transmission from the client to the server is completed. At this time, although the client cannot send data, it can still accept the data sent to the client by the server, that is, the connection from the server to the client has not been closed.

4. The server sends a FIN setting 1 message to the client, closes the data transmission from the server to the client, waits for the client's ACK confirmation reply, and enters the LAST_ACK state at the same time. After receiving the FIN setting 1 message, the client replies to the ACK confirmation message and enters the TIME_WAIT state. After twice the maximum message lifetime (MSL), TCP deletes the original link record and returns to the initial CLOSED state. After receiving the ACK confirmation message, the server enters the CLOSED state and completes the two-way closure of the link.

The four-time disconnection process of TCP/IP is shown in the figure:

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