The network protocol is hierarchical, and the hierarchical concept is similar to function encapsulation, continuously providing more advanced and abstract interfaces, and finally providing them to customers. For layered protocols, the entire protocol completes one thing together. Each layer completes the functions of this layer based on the interface of this layer or lower layer and provides interfaces for higher layers. That is, for each layer, there are the following two The main function:
To give an example, to realize the function of calculator calculation, we implement a calculator protocol, which is divided into the following levels:
Suppose that the manufacturer builds a handwritten calculator based on the calculator protocol. When the user needs to perform
1+1calculations, input the calculation requirements by handwriting, that is, a handwritten picture, and then the user input layer converts the handwritten picture into a logical language
R=1+1and calls the logic The compilation layer is implemented; the logic compilation layer converts it into assembly code
ADD R 1 1and calls the hardware layer for implementation; the hardware layer runs the assembly code to get the result R to be 2, and the result is fed back to the logic compilation layer; the logic compilation layer receives the result of the hardware layer And return it to the user input layer; the user input layer converts the result into a handwritten number 2 and feeds it back to the user.
The advantage of this layered protocol is that the layers are independent of each other, with only the connection on the interface, which can be easily replaced. Taking the above calculator protocol as an example, the user input layer can use a touch screen or a keyboard, and only need to convert the input (touch screen input or keyboard input) into a logical language in a unified format; it can also be used in the logic compilation layer Different compilation software only needs to have the same input and output format interface; the same is true for the hardware layer, you can use AMD's cpu or Intel's cpu, you only need to provide the same interface for the logic compilation layer. Layers are independent of each other, and layers of abstraction.
The TCP/IP layering is born out of the OSI layering. The above two layers are shown in the following figure:
The OSI layering is divided into 7 layers, and the TCP/IP model is divided into 5 layers. 1. consider the OSI layering, and take an operation in online battle as an example, which is to control a certain character to release a specified direction in a specified direction. Skills (the actual game will be different):
For the layering of TCP/IP, the application layer, presentation layer, and session layer in OSI are unified into the application layer. Therefore, examples of layer 5 packets and corresponding protocols are:
For the data link layer and the physical layer, its function is to send data from one node to an adjacent node; for the network layer, its function is to send data from one host to another host (may span many nodes, not Concerned about whether there is an error); For the transmission layer, it is necessary to ensure that the data is sent from one host to another without errors. The transmission layer protocol may call the network layer transmission multiple times in one transmission; the application layer is the protocol finally contacted by the user to achieve specific functions For example, HTTPS realizes web page access, and FTP realizes data transmission, as shown in the following figure: