Ultra-detailed explanation of what is three-way handshake, waving four times! After reading you will not hit me

最近可能是和网络干上了,就想写一点儿和网络有关的东西。
今天给大家讲一讲什么是三次握手和四次挥手。

In tcp / ip 4 protocol, the network communication model is divided into four layers, namely application layer, transport layer, network layer, the network access layer . Today we are saying this, located in the transport layer.
tcp protocol in the transport layer protocol can be described as a household name, it is a stable-oriented transport protocol connection, connection-oriented since he, then, when we use and end, it must be created and closed connections.
And our three-way handshake is what happens when tcp connection protocol. First of all we have a few English words, oh, no, it should be abbreviated English words.
SYN: Synchronization: synchronization
Seq: Sequence: Sequence
Ack: Acknowledgment: Reply
Fin: Finish: End

看到这里肯定有暴躁的看官老爷要问了,妈的,不好好讲主题,说这几个英文单词有什么用
而我也知道,如果今天不给一个令人满意的答复是不可能活着走出去的, 听我细细到来

I hung from the Internet following a stolen map
Here Insert Picture Description
as shown is a tcp packet structure, next to me while listening to and watching the map, will soon understand.
The figure of 32 numbers we use to represent lowercase seq, ack use 32-bit acknowledgment number to represent
and SYN, ACK flag will use capital letters to express themselves, it must not be mixed up.

接下来就是大家最喜欢的名词解释环节

Glossary

SEQ (lowercase): we all know, TCP is a connection-oriented, reliable byte stream based services, and to ensure that the order of data transfer time, it is an important embodiment of reliability. And we give is through tcp packets each plus seq serial number to determine the order. Further, what is to be noted, is based on the number of characters transmitted stream, rather than based on the sequence of the segment of the transmission, that is to say, if that segment A segment is located in the B -phase o in front of the end of a packet, segment a has 1000 bytes, the sequence number and a is 1, then the B segment is a sequence number to 1001 , Tell me master savor the mystery.
** ack **: represents the server expects to receive next sequence number is the number, so you see below will find seq great value returned by the server is always sent ack than the client
ACK (uppercase): We can see the It stands the figure that a few capital letters, a total of six groups, TCP packet header end six bits, corresponding to the six flags, six groups above the letters on the corresponding six markers, ACK is one of First, when its value is 1, on behalf of a party has received the request.
** SYN ** (in uppercase): one of the six flag is representative of a request to establish a connection.

Three-way handshake

To establish a connection to our clients (request resources) and server (send resources) by sending three packets, so we will call it the image of the three-way handshake.

First

When the first transmission, the transmission packet from the client to the server, wherein the SYN flag bit is 1 (indicating a synchronous request, i.e., it is representative of a request to establish a connection to the client and server end hope ). ACK value of 0 it is affirmed, and then sends a random number to generate a random number X, here assumed to be 1000. With the client and enter the SYN sending state.

Second

Second transmission time, as the client sends the server packet, the SYN and ACK flags two bits are 1, transmission sequence number Y (also randomly generated), as the acknowledgment number 1001 (acknowledgment number in the first plus a number of packet transmission based on the transmission sequence number, for convenience of explanation, it is referred to herein as 1). From this moment, the server enters a reception state synchronization (SYN).

Final

Third sending, and the client sends a SYN ACK packet sent by the server after receiving the returned ACK packet representative confirmed, accepted sequence number Y + 1, then on, the client and server are entered on the connection setup state, three-way handshake is completed. Congratulations, congratulations.

Tiny eggs

为什么是三次握手,两次握手不可以吗?

Since people are called three-way handshake, and certainly did it any better. . . . Tell me what you do not impulse ,, master the hands of the knife down, listen to me slowly come. When we shook hands on it through twice to establish a connection, the client sends a connection request to the server A, but because of network latency, at the time the server has not received the request, the client in a hurry, made a second time after the connection request, the connection is successful, we contented complete unknown transaction, then a connection was sent to the server, the server for confirmation, but the client has delayed a request to do a deal with an invalid Therefore, the server will be the same as the Cowherd and Weaver Girl, etc., which will no doubt spend a lot of resources of our server, and may also cause a "deadlock" in addition to the above, because of space problems, here described without, interest objective can master their own Baidu.

当我们的连接建立后,客户端出现故障怎么办?

When our client and server being pleasant transaction, the client suddenly fails, we can not continue to send data, at this time, the server will not stop trading immediately, but will be in small pieces of time, be within the specified number of packet inspection, still can not get a response, it will close the connection.

Four waving

First

Client sends a FIN + ACK request indicates a request for ending the connection

Second

The server receives the client's request, return ACK acknowledged receipt of the request, and have the client continues to wait for their own sends all data is completed.

Third

After the service side of the data has been sent, sends FIN + ACK to the client, which indicates the data has been sent up here.

final

The client sends to the server ACK, indicates that the received, and then ease off the server, the client will then wait for a while, if there is no reply, then it is considered the server is off, and he also closed.

到此为止,四次挥手也完毕。。。。可喜可贺,可喜可贺

Tell me the time and went to say goodbye to a classic
final, small shark I wish you all the best, good health, eat fruit every day !!!

Released three original articles · won praise 2 · Views 1141

Guess you like

Origin blog.csdn.net/weixin_44880685/article/details/104719615