In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the seven-layer model of the network and the principle of TCP/UDP". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the principle of the seven-layer model of the network and TCP/UDP".
In order to enable different computer manufacturers around the world to communicate harmoniously with each other, it is necessary to establish a global general protocol to standardize the communication interface between different manufacturers. this is the origin of the seven-layer network model. This paper will first introduce the functions of the seven-layer model of the network, and then explain the two important protocols of the transport layer: TCP and UDP, and focus on the process of three-way handshake and four waves in TCP protocol.
1. Network seven-layer model
With regard to the seven-layer model of the network, we first show its function with a legend:
Application layer: mainly refers to the application part, such as our Java program. The data generated by the application layer becomes application layer data. Typical application layer protocols, such as HTTP protocol and dubbo rpc protocol, are defined by our application layer program itself.
Presentation layer: this layer mainly performs some format conversion, encryption and decryption or compression and decompression of the data in the application layer.
Session layer: the main role of the session layer is to be responsible for the establishment, management and termination of sessions between processes.
Transport layer: the transport layer provides a port-to-port data transmission service between two machines, because the application layer, presentation layer and session layer are all aimed at an application process, and the process is bound to the port. however, there can be multiple processes on the same server, so the transport layer provides this different port-to-port access to distinguish communication services between different processes. The most typical protocols in the transport layer are TCP and UDP protocols. TCP provides connection-oriented and reliable data transmission services, while UDP is connectionless and unreliable data transmission services. In the figure above, we can also see that after passing through the transport layer, the data will be added with TCP or UDP headers to implement the functions of different transport layer protocols.
Network layer: the transport layer provides the port-to-port transmission service on the same host, while the network layer provides the connection service between different hosts. The most typical network layer protocol is the IP protocol. The network layer adds the current data packet to an IP header to realize the addressing of the target machine.
Data link layer: this layer is the layer that undertakes software and hardware. Because it sends current datagrams to unstable physical layer hardware for transmission, in order to ensure the integrity and reliability of data, the data link layer provides mechanisms such as verification, confirmation and feedback to provide reliable Datagram transmission services.
Physical layer: the main function of the physical layer is to convert 0101 binary bit stream data into optical signals for transmission on physical media.
The seven-layer model of the network is mainly a specification, and in order to achieve different functions on each layer, each computer manufacturer will implement its own protocols, and the identification of these protocols is carried out through some protocol headers. For example, in the figure above, after each layer is encapsulated, the data will add its own protocol header, and when the data is transmitted through the room medium to the target machine, it will be reversed. The data is parsed layer by layer, and the process of parsing is to realize the related functions of this layer according to the header information of each layer.
In addition, the network seven-layer model is a more idealized model, and the network five-layer model is widely used now. the main difference between the five-layer model and the seven-layer model is that the application layer, presentation layer and session layer are divided into the application layer, and the related functions are realized by the application.
2. TCP and UDP
In the process of our application development, we do not need to pay too much attention to the underlying related functions, which only need the relevant service providers to provide the corresponding functions. In the transport layer, however, we need to pay special attention to two protocols that are now widely used: TCP and UDP. The main differences between the two protocols are as follows:
TCPUDP provides data reliability guarantee for connection-oriented, no data reliability guarantee, relatively slow speed, faster speed, more resources and less resources.
With regard to TCP and UDP, we can see that these two protocols have their own distinct characteristics: although TCP takes up a lot of resources and its speed is relatively slow, it provides reliable data transmission services, which is very necessary in most Internet services. Although UDP does not provide reliable data guarantee, it is very fast and takes up less resources, which is very useful in some scenarios with low data reliability, such as audio and video services, Internet of things data reporting service, and so on. In these cases, it is acceptable to lose one or two frames of data.
The difference in resource occupation between TCP and UDP is reflected not only in the mode of data transmission, but also in the format of data transmission. For data transmission mode, TCP sends data every time according to the way of time window, and it needs to wait for each Datagram to respond to the data sender ACK, then the data of the next data window will be sent. If any Datagram in the current window is not sent successfully, the data in the whole window will be re-sent. On the other hand, UDP does not have the concept of window and the corresponding ACK mechanism. After it gets each Datagram, it simply encapsulates the UDP protocol header for it and then sends it out, regardless of whether the data is sent successfully or not, so UDP transmission is much faster than TCP. As for the data transmission format, we will explain it in TCP and UDP Datagram format, as follows: TCP Datagram format:
It can be seen that the header of TCP Datagram contains not only the source port number and destination port number, but also the sequence number, confirmation number, header length, flag bit and other information. generally speaking, excluding the real data part, the number of bits occupied by the header information reaches 192 bits. of course, the main function of so many fields is to realize the connection-oriented reliable transmission function of TCP. The following is the format of the UDP Datagram:
As you can see, the packet format of UDP is very concise compared with TCP, and its header is mainly source port number, destination port number, length and checksum field, which take up a total of 8 bytes. This is another reason why the transmission rate of UDP protocol is very fast.
2.1 three handshakes and four waves
TCP is a connection-oriented transport layer protocol that provides reliable transmission services. Its reliability is mainly guaranteed by the ACK mechanism when each Datagram is sent, while the establishment and release of the connection is mainly achieved by three-way handshaking and four-time waving. Here is the process of three handshakes and four waves:
For a three-way handshake, the overall process is as follows:
First of all, the client will send a request to establish a connection, with SYN=1 and seq=x in its flag bit. According to the explanation of the previous TCP header information, the SYN=1 here indicates the request to establish a connection, while seq=x is only a sequence number of the current request. Different requests have different sequence numbers, and the reason for adding this sequence number is also to associate it with the response request of the server.
After the server receives the client's request to establish a connection, it will return SYN=1, ACK=1, seq=y, ack_seq=x+1, where SYN=1 and ACK=1 represent the agreed response to the client's request to establish a connection, seq=y indicates that this is a data transmission from the server, and ack_seq=x+1 indicates that it is a response to the client's seq=x request
When the client receives the response from the server, the client can confirm that the server can receive and send data normally, and the server can also confirm that the client can send the request normally when it receives the first request from the client. At this time, the client will send an ACK=1, seq=x+1, ack_seq=y+1 to the server, and the server will complete the establishment of the connection after receiving it.
As you can see, the first two requests are necessary to establish a connection, and there are two main reasons why the client sends the third request:
Allows the server to ensure that the client is able to send and receive requests normally
Because the connection is established on an unstable network, it is possible that the first request was sent by the client at a certain point in time, but due to the network delay, it took a long time for the server to receive the request. however, at this time, the server does not know whether the request established by the connection is a normal request, so it will normally send a response agreeing to establish the connection to the client. If the first request is caused by a network delay, the client will not send a third handshake to the server, and the server will not establish a connection after waiting for the timeout.
For four waves, it is initiated by the client after the interaction between the client and the server is completed. The main process of the four waves is as follows:
The client will first send a FIN=1, seq=u to the server. According to the explanation of the previous TCP header information, we know that FIN=1 indicates that this is a disconnected request, while seq=u identifies a serial number of this request.
After the server receives the disconnection request from the client, it will send a response of ACK=1, seq=v, ack_seq=u+1 to the client, where the seq=v still indicates the sequence number of the current request, while ack_seq=u+1 indicates that this is a response to the disconnection request from the seq=u sent by the client. However, it should be noted that this request does not mean that the server agrees to disconnect, it is only a half-closed state. Because at this time, the server may still have data being processed and not sent to the client, the server will complete these disconnected tasks.
After the server completes the preparation for disconnection, it will send a response of FIN=1, ACK=1, seq=w, ack_seq=u+1 to the client. Note that the client has been waiting during this process. There is an extra FIN=1 compared to the previous response, which means that the request to confirm the disconnection is currently being made
After the client receives the response from the server, it will send an ACK=1, seq=u+1, ack_seq=w+1 response to the server, indicating that it agrees to disconnect. The server will disconnect after receiving it, while the client will wait for a short period of time and then disconnect itself.
3. Summary
This paper first explains the seven-layer model of OSI network, explains in detail the function of each layer in the model, then explains the main differences between TCP and UDP in the transport layer, and compares the two protocols in terms of transmission mode and data format. Finally, it explains the main process of three-way handshake and four-wave hand in TCP protocol, and explains the function of each step in detail.
Thank you for your reading. the above is the content of "what is the seven-layer model of the network and the principle of TCP/UDP". After the study of this article, I believe you have a deeper understanding of what the seven-layer model of the network and the principle of TCP/UDP are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.