In order to enable different computer manufacturers around the world to communicate with each other in a coordinated manner, it is necessary to establish a universal protocol to standardize the communication interfaces between manufacturers. This is the origin of the seven-layer network model. This article will first introduce the functions of the seven-layer network model, and then explain the two important protocols of the transport layer: TCP and UDP protocols, and will focus on the three-way handshake and four-way handshake process in the TCP protocol. 1. Seven-layer network model Regarding the seven-layer network model, we first use an illustration to demonstrate its functions:
The seven-layer network model mainly provides a specification. In order to achieve different functions at each layer, each computer manufacturer will implement its own protocol. The identification of these protocols is carried out through some protocol headers. For example, in the figure above, after the data is encapsulated at each layer, its own protocol header will be added to it. When the data is transmitted to the target machine through the indoor medium, it will, in turn, parse the data layer by layer. The parsing process is actually to implement the relevant functions of each layer according to the header information of each layer. In addition, the seven-layer network model is a relatively idealized model. The five-layer network model is now more widely used. The main difference between the five-layer model and the seven-layer model is that the application layer, presentation layer, and session layer are unified into the application layer, and the application program implements its related functions. 2. TCP vs UDP In the process of application development, we don't need to pay too much attention to the underlying functions. We only need the relevant service providers to provide the corresponding functions. However, in the transport layer, we need to pay special attention to the two widely used protocols: TCP and UDP. The main differences between these two protocols are as follows: TCPUDP Connection-oriented Connectionless Provides data reliability guarantee Does not provide data reliability guarantee Relatively slow Speed Fast Occupies more resources Occupies less resources Regarding TCP and UDP, we can see that these two protocols each have very distinct characteristics: although TCP occupies more resources and is relatively slow, it provides reliable data transmission services, which is very necessary in most Internet services; and although UDP does not provide reliable data guarantees, it is very fast and occupies fewer resources, which is very useful in some scenarios with low data reliability, such as audio and video services, IoT data reporting services, etc. In these cases, the loss of one or two frames of data is acceptable. The difference between TCP and UDP in resource usage is not only reflected in the data transmission method, but also in the data transmission format. For data transmission methods, TCP sends data one datagram at a time window each time, and needs to wait for each datagram to respond to the data sender with an ACK. Only then will the data of the next data window be sent. If any datagram in the current window is not sent successfully, the data in the entire window will be resent; UDP does not have the concept of windows and the corresponding ACK mechanism. After obtaining each datagram, it simply encapsulates the UDP protocol header for it and then sends it out. It does not care whether the data is sent successfully. Therefore, UDP transmission is much faster than TCP. For the data transmission format, here we will explain the format of TCP and UDP datagrams. The following is the TCP datagram format: As you can see, the header of a TCP datagram contains not only the source port number and the destination port number, but also the sequence number, confirmation number, header length, flags, and other information. In general, excluding the actual data part, the number of bytes occupied by the header information reaches 192 bytes. Of course, the main purpose of so many fields is to realize the TCP connection-oriented reliable transmission function. The following is the format of a UDP datagram: As you can see, the UDP packet format is much simpler than TCP, and its header mainly contains only the source port number, destination port number, length and checksum fields, which occupy a total of 8 bytes. This is another reason why the UDP protocol has a very fast transmission rate. 2. Three-way handshake and four-way wave TCP is a connection-oriented transport layer protocol that provides reliable transmission services. Its reliability is mainly achieved through the ACK mechanism when each datagram is sent, and its connection establishment and release are mainly achieved through three-way handshake and four-way handshake. The following is the process of the three-way handshake and four-way handshake: For the three-way handshake, the overall process is as follows:
As you can see, the first two requests are necessary to establish a connection, and the client sends the third request for two main reasons:
The four-wave handshake is initiated by the client after the client and server complete the interaction. The main process of the four-wave handshake is as follows:
3. Summary This article first explains the OSI network seven-layer model, and explains in detail the role of each layer in the model. Then it explains the main differences between TCP and UDP in the transport layer, and compares the two protocols in terms of transmission method and transmission data format. Finally, it explains the main process of the three-way handshake and four-way handshake in the TCP protocol, and explains in detail the role of each step. |
<<: Android Network Programming-TCP/IP Protocol
>>: How does DNS work? See how this "translator" converts domain names and IP addresses
Some people say that the most profound change tha...
TMThosting has launched a summer promotion, with ...
[[376851]] Consider this question: how many ways ...
If we choose the most used function of mobile pho...
According to research firm IDC, spending on the I...
According to the policies of communication regula...
CUBECLOUD is a Chinese hosting company establishe...
It's been a while since I shared information ...
The development of 5G has now become another hot ...
TmhHost's back-to-school season event is stil...
Wireless routers have entered thousands of househ...
Yes, you read that right. With the exposure of th...
[[375802]] This article is reprinted from the WeC...
This article briefly summarizes the history of te...
GreenCloudVPS released an email about its 8th ann...