picture What is TCPTCP is a connection-oriented, reliable, byte stream-based transport layer protocol. connectThe so-called connection is actually the sum of state information that ensures reliability and flow control, including sokict, sliding window and sequence number. reliabilityTCP uses a series of control mechanisms such as sequence numbers, retransmission mechanisms, sliding windows, etc. to ensure that data is not duplicated, lost, and processed in order by the receiving end. Byte StreamTCP data is based on byte streams, so it is unbounded and can be infinitely large. TCP can send data to the receiving end in an orderly manner through a fragmentation mechanism. TCP StructureThe TCP header is 20 bytes without the "option" field. It includes:
It should be noted here that the "Option" field is used to assist in solving reliability issues. Because the length of this field is uncertain, the "Header Length" field is needed to indicate the length of the TCP header. TCP three-way handshake processpicture What is a three-way handshakeTCP is connection-based, so a connection must be established before it can be used. The process of TCP establishing a connection is based on a three-way handshake.
At this point, the TCP connection is established. Note that data can be transmitted after the third handshake. Data cannot be transmitted before this. Why three-way handshake?Generally, everyone thinks that the three-way handshake is to ensure that both the client and the server can confirm that they have established a one-way connection with the receiving end and that they can send and receive data successfully. This answer itself is not wrong, but it is too crude. Since the handshake is to ensure the establishment of the connection, we must first know what a TCP connection is. A TCP connection is the sum of state information that ensures reliability and flow control, including sockets, sequence numbers, and sliding windows. The sequence number is crucial here. It is the key to ensure that messages are not duplicated, lost, and in order. Therefore, the purpose here is to ensure the synchronization of the sequence number. The client sends an initial sequence number to the server, and the server replies syn+ack, telling the client that the sequence number has been received and sending the server's initial sequence number to the client. After receiving it, the client also replies to the server to indicate that the sequence number has been received, so that both parties can ensure that the sequence numbers are synchronized. But this is not the most important reason. The most important reason is to prevent the historical connection from being initialized and reconnected. For example, there is such a situation that the client sends a syn packet to the server, but the network is blocked and the server does not receive it, so the server will not reply. The client will resend the syn packet if it does not receive a reply, but at this time the server receives the first syn packet and replies to the client. At this time, the client will compare and verify whether this is the latest syn reply packet sent by itself. If not, it will send a rst packet to the server, indicating that it requires the server to terminate the connection. This is also the meaning of the three-way handshake. If there is no third handshake, then after the above situation occurs, the server will create a connection for each syn request, and the connection needs to occupy memory, which will consume a lot of resources. This will cause a waste of resources, so the three-way handshake is necessary. So is a four-way handshake possible? A four-way handshake is also possible. In fact, the four-way handshake is that the client sends a syn packet to the server, the server replies with an ack packet, the server sends a syn packet to the client, and the client replies with an ack packet. The second handshake in the three-way handshake replies with a syn+ack packet, which is equivalent to merging the middle two of the four handshakes, so a three-way handshake is the best. picture Four waves processTCP is a bidirectional connection, so the connection in both directions must be disconnected.
In the world of network transmission, there are two values used to indicate packet failure:
Therefore, in general, MSL will be greater than the time it takes for TTL to decrease to 0. Why is the MSL twice as high here?Because when the client receives the fin packet from the server, it will reply ack to the server, but the client does not know whether the ack is sent successfully, so the client needs to confirm that the server has received it successfully before it can be set to the close state. How to confirm it? Because of the existence of the failed retransmission mechanism, if the server does not receive the ack due to network congestion, the server will send a fin again. An ack packet and another fin packet is 2 times the MSL. The timing of MSL starts from receiving the fin packet and sending the ack packet. In addition to the above mentioned guarantee that the client's ack is sent to the server and is correctly received, it is also ensured that the party whose connection is being closed can be closed correctly. It can also ensure that old connections blocked in the network are received when the port is reused, which will cause data confusion, and time_wait can ensure that all connections in the network are discarded. The default MSL is 30 seconds. It should be noted that too many time_wait states will occupy memory resources and port resources, so it is not advisable to have too many. Why four waves?TCP is a two-way connection. The client sends a FIN packet to the server, and the server replies with an ACK. This is just the client telling the server not to send data to the server anymore. The server also needs to tell the client that it will no longer send data to the client. In other words, the server also needs to send a fin packet to the client, and the client also needs to reply with an ack packet to the server. Only then can the server and the client enter the close state. After the server receives the FIN packet sent by the client and replies with an ACK packet, it cannot immediately send a FIN packet to the sender because there may still be connections processing data. It must wait until the data is processed before sending a FIN packet to the client. For this reason, the two middle steps cannot be combined like the three-way handshake. |
<<: Learn VLAN division from scratch to double your network performance!
>>: ERP, CRM, SRM, PLM, HRM, OA...what do they all mean?
As the largest communications exhibition in Asia ...
According to an IDC report, by 2018, 67% of the w...
5G is good, 5G is wonderful, and 5G will be great...
[[348875]] This is not the first time that 5G has...
Network infrastructure is expanding to multiple c...
Private 5G networks are attractive to the largest...
We have received the official announcement from D...
Why are the three major operators called the thre...
Aruba, a subsidiary of Hewlett Packard Enterprise...
Maxthon Hosting is a long-established foreign VPS...
5G can help transform the manufacturing industry....
retinaface face detection algorithm dessert I hav...
HostBrr is a Danish hosting company founded in 20...
According to some users, in order to improve the ...
On October 19, the "2018 University Smart Ed...