The most straightforward image of TCP three-way handshake

Why establish a connection requires three-way handshake?

First is very clear two-way handshake is the most basic. The first handshake, the client made a connection request message to the server, the server receives information know that they can connect with the client is successful, but the client does not know at this time whether the server has received its request, so after the service termination after receiving the response message, the client service side to get feedback before deciding on their own with the server is connected, this is the second handshake.

The client can only determine their own connection to the server to begin the data. So two-way handshake is certainly essential.

—————————————————————————————————————————

See here, you may ask, why it needs to third handshake? We look, if it is assumed that there is no third handshake, but twice after the handshake we think the connection is successful, then what happens? Third handshake has failed to prevent the connection request segment suddenly spread to the server, resulting in an error.

For example, a request to initiate encounters like this: The client sends a connection request to the first residence for some reason that led to delays in the network node, a point in time until the connection is released before reaching the server, which is a long failure message, but this time the server still think it is to establish a client connection request first handshake, then the server responds to the client, second handshake.

If only two shook hands, then here, the connection is established, but this time the client does not have any data to send, while the server is still waiting for good news silly, causing great waste of resources. Third handshake is required, only the client to respond again, we can avoid this situation.

—————————————————————————————————————————

If you think the above described too professional, or a little Meng Meng, it does not matter, let's take a case to illustrate life.

TCP three-way handshake is like a night in high wind black night, a man in the district where you walk, not far from the district where the sight of a beautiful sister oncoming, but a bit dark because street lights and other reasons not 100% confirmed, so to determine whether the other party recognized by waving their own way.

The first thing you waved to sister (syn), sister saw you waving to her, you nod out a smile (ack). After you see sister smile confirmed his sister successfully identified (enter estalished state).

But sister a little bit embarrassed, look at his friends around, is it possible that you are looking at someone else, she needs to be sure. After the sister also beckoned to you (syn), you see after waving to his sister know each other is looking for his confirmation, then nodded his head out of the smile (ack), sister to see each other smile confirmed you are in yourself to say hello to (enter the established state).

So they speed up the pace, they came together and embraced each other with each other.

Let's look at this process in a total of four actions,

You beckon sister sister nodded and smiled and waved you nod and smile

Where the sister continued for two actions, first nod and smile (reply to the other side), then waved again (to seek confirmation), we can in fact these two actions into one action, nodding and smiling (syn + ack) waving at the same time. So these four actions to simplify into three movements.

You beckon sister nodded and smiled and waved you nod and smile

This is the essence of three-way handshake, the middle of the action is a merger of the two actions. Through this case, I wonder if you shake hands on the TCP three-way, there is no further understanding.

After the handshake is complete, start TCP data transmission

TCP data transmission Taking two people exchanges, there is a certain distance, need each other repeatedly confirmed hear his words.

You shout a word (data), sister heard you want to reply after I heard and (ack). If you shouted, half did not hear the reply sister, you will be very low, like love, you enthusiastically, and sister fits and starts, so you perseverance, one is not, twice, not to three times, this is the tcp retransmission.

It is also possible that sister know your intent, but a little shy sister, also has yet to respond, or you did not receive a reply sister, that you did not receive a reply sister. Your sister does not know if in the end you like it or not, you have no opinion, it does not matter, man Well? To be proactive, retransmission look like.

 

Since it will be retransmitted, it is possible to hear the sister twice in the same sentence, which is to go heavy. For retransmission and to re-work the two network operating system kernel module has helped us to deal with, and we ignore them.

Published 124 original articles · won praise 21 · views 120 000 +

Guess you like

Origin blog.csdn.net/qq_38890412/article/details/104709435