An article to understand TCP, UDP concepts and TCP three-way handshake connection

An article to understand TCP, UDP concepts and TCP three-way handshake connection

[[245408]]

OSI computer network 7-layer model

TCP/IP four-layer network model

The transport layer provides logical communication between applications (end-to-end), the network layer provides host-to-host communication, and the transport layer provides reliable services.

The handshake often mentioned in TCP refers to the process of connection definition and connection establishment. The IP protocol is connectionless, but TCP is connection-based.

Port: The data link layer relies on MAC address addressing, the network interface layer relies on IP address addressing, and the transport layer relies on port number addressing. The port is the address for inter-layer exchange between various protocol processes and transmission entities in the application layer.

Port number: a number that identifies different processes, 16 bits, 2 to the 16th power, and only meaningful locally. There are three types, one is the reserved port, such as ftp is 21, 20, dns is 53, http is port 80, smtp is 25, etc. The second is the registered port, and the third is the client port number, also called the temporary port (the first two are called server ports)

Socket: It is composed of host IP + port number. Only through IP address and port number can a connected port be uniquely identified. It uniquely identifies an application process in a host in the network.

udp:

User Datagram Protocol implements connectionless service, no confirmation, unreliable delivery, low overhead, short delay, no congestion control, and is mainly used in real-time applications such as IP telephony, QQ, video conferencing, etc. UDP datagram is only a part of IP datagram.

TCP

That is, the Transmission Control Protocol, which implements a connection-oriented service and provides a full-duplex, reliable logical channel to the upper side, with reliable delivery and high overhead. Note that the TCP connection channel is logical and invisible to routers, similar to a virtual circuit.

Three segments of a TCP connection:

Establish, transmit, and release. The endpoint of the connection is called a socket, which is determined by the only two communication endpoints. It adopts the CS architecture (client-server model). The establishment of the TCP transmission connection adopts a three-way handshake (which can prevent errors in the transmission of the message segment during the connection establishment).

The main purpose of the TCP three-way handshake is to ensure that the connection is duplex, and reliability is more guaranteed by the retransmission mechanism.

First handshake: When establishing a connection, the client sends a syn packet (syn=j) to the server and enters the SYN_SEND state, waiting for the server to confirm;

Second handshake: After receiving the SYN packet, the server must confirm the client's SYN (ack=j+1) and send a SYN packet (syn=k), i.e., a SYN+ACK packet. At this time, the server enters the SYN_RECV state.

The third handshake: The client receives the SYN+ACK packet from the server and sends a confirmation packet ACK (ack=k+1) to the server. After this packet is sent, the client and server enter the ESTABLISHED state, completing the three-way handshake.

Through this three-way handshake, the client and the server establish a reliable duplex connection and start transmitting data.

But why is it necessary to perform a three-way handshake to ensure a duplex connection? Isn't it enough to do it once? Isn't it enough to do it twice? Let's take an example of two people communicating in language in real life to simulate a three-way handshake.

First handshake:

In an exam, student A and student B are good friends. At this time, A wants to copy the result of the last big question on B's paper.

A whispers to B, "Little B, let me copy the answer to the first question on your test paper. I can't figure it out." There are two possible results:

1. If student B concentrates on answering the questions and does not pay attention to student A's request, then the communication between student A and student B fails. In other words, student B cannot receive the information from student A, and the communication must have failed.

2. If little B hears a's whisper, then it means that the first conversation (handshake) is successful. It means that b can accept a's request to b.

Second handshake:

When Xiao B hears A's request to plagiarize, there are two possible outcomes:

1. If student B is nervous, he can hear what student A said, but he doesn’t know which question student A wants to copy, so he just says casually: I don’t know either. Student A gets angry when he hears this. Can we still be friends? I misjudged you! OK, the communication between student A and student B fails. This means that student B fails to make a correct response.

2. If student B hears and understands student A's request to copy, then student B will make a correct response and tell A the result of the first question. Moreover, student B and student A are close friends, and student B is afraid that student A will not be able to copy. So he asks: "A, have you copied?" This is equivalent to the second successful handshake. The first two conversations (handshakes) prove that student B can hear and understand what student A said, and can make a correct response to student A's request. Then the third handshake will be carried out.

The third handshake:

A gets the correct feedback from student B. There are two results:

1. If student A is very happy, he will start copying immediately! A will forget everything else and copy quickly. As a result, he will not pay attention to student B's *** sentence "Have you finished cooking?", which makes student B wait for a reply for several minutes. B is very disappointed and thinks: Good for you, you copied it and forgot about me, well, I will never care about you again, ***ab still fails to communicate. This means that when student A cannot respond to student B, ab fails to communicate.

2. If student A notices student B's feedback and question, then student A says to student B: I have copied it. Then the third handshake between student A and student B is successful. A and student B have established a pleasant and smooth communication channel. Then student A and student B can continue to happily communicate the answers.

Proven by the second and third handshakes:

Student A can hear clearly what Student B said, and Student A can give correct feedback. It can be seen that if Student A and Student B have effective and pleasant communication, then the three-handshake process is necessary.

Similarly, we can understand why TCP needs a three-way handshake:

In fact, the handshake is performed at least three times in order to ensure that the requests from both sides can be identified. The first two (first and second) handshakes are performed to ensure that the server can receive the information from the client and make a correct response, and the last two (second and third) handshakes are performed to ensure that the client can receive the information from the server and make a correct response.

<<:  Wide Area Networks: What You Need to Know in the Internet of Things Era

>>:  Wi-Fi Alliance wants to simplify the numbering and use numbers instead of "802.11ac"

Blog    
Blog    

Recommend

5G network needs to save money by relying on these four key technologies

[[385335]] This article is reprinted from the WeC...

The battle of data center network switching equipment architecture

Switching technology is one of the important tech...

How Desktop Cloud Helps Application Innovation

Desktop cloud (also known as cloud desktop, deskt...

Unlocking the secrets of network security: data encryption and key management

In this digital age where data is like gold, how ...

Essential HTTP knowledge for front-end developers! Just read this article! !

HTTP Origin HTTP was initiated by Tim Berners-Lee...

Ctrip Optical Network's Practice of Resisting Cable Disruption

About the Author Lightworker, a network technolog...

5G will become the golden key to open the era of the Internet of Things

The Internet of Things is not new. At the beginni...

4G is still growing, and 5G is still a long way off

Recently, the Ministry of Industry and Informatio...

5G is coming, but how fast?

Wireless networking is truly part of the culture ...

Four SD-WAN misconceptions

When any technology or service is sold in large q...

2021 is the year of the explosion of the cellular IoT module industry

According to a new research report from IoT analy...