When you see this article, your computer sends a lot of HTTP requests to the segment server, and then the page is displayed on your computer. How on earth do these HTTP from one computer to another computer (server), and how do they communicate? This involves the Internet communication protocol.
We often hear the HTTP protocol, HTTP is transmitted through TCP, these two are the two layer protocols. Internet protocol can be divided into five layers, as shown in the figure above.
The bottom layer protocol is the “physical layer”. The physical connection between devices can be either wired (optical fiber, optical cable) or wireless, which is also the cornerstone of Internet communication. Any text, picture or video we see is essentially the continuous transmission of electrical signals such as 0 and 1 through these physical layer lines.
A long string of continuous electrical signals such as 0 and 1 can not accurately express the meaning, which gives birth to the second layer protocol “link layer”. The link layer can also be called “Ethernet Protocol”. It groups electrical signals such as 0 and 1. How many are counted as a group, and what does each group mean.
There is a core problem here. Although there are physical circuits and groups of various combinations of electrical signals, how do they get from one computer to another?
The computer sends and receives signals from the outside through the network card. Each network card has its own MAC address (equivalent to ID). The MAC address identity of each computer network card is unique in the world, which was made in the factory.
When several computers are in the same network (local area network), for example, there are four computers a, B, C and D, and computer a wants to transmit information to computer C, computer a will not “directly deliver” the information to computer C, but “broadcast” the information, that is, advertising.
The network cards of B, C and D computers in the same network will receive the electrical signals sent by the network card of computer A. However, when the network card of computer a sends the signal, the MAC address of the network card of the receiver is marked in the signal. For example, the MAC address of the network card of computer C is marked as the receiver. After receiving the electrical signal, B and d find that the receiver is not themselves and will not process it, Only C will find that the receiver will process the received signals.
You may wonder why the signal of a doesn’t go directly to C? The key to this is: if one of the 1 million computers made by apple is specified, the information must only be sent to one of the 10 million computers made by Dell? In fact, many modern electronic devices use this “broadcast” form of communication, such as GPS satellite. GPS satellite will not know your mobile phone. It will send electromagnetic wave signals to the whole airspace. Every mobile phone will receive such electromagnetic wave signals, but some mobile phones have the right to process and analyze the signals, and some mobile phones have no right to process them.
The communication through MAC address is the “Ethernet” protocol of the second layer, which is mainly used to send signals from computer a to computer C in the same network. This layer can only communicate with computers in the same network. If computers in different networks want to complete communication, they need the participation of the third layer, namely network layer, IP protocol. This is the IP address we are familiar with. For example, sending data from Beijing to Shanghai needs the help of IP address.
The signal of IP protocol defines the IP address of the remote target device, but it should be noted that the electrical signal will not fly directly from Beijing to Shanghai. Your computer is in a group of networks. Each group of networks has a switch role. The switches of different network groups are in a group of networks at a higher level. The network at a higher level has a group of networks at a higher level. There are also various switches in the city, and these switches will be in a group of networks. These networks are broadcasting signals layer by layer through “broadcasting”. Each network group has its own IP address. The IP address of the target party is defined in your electrical signal. Some network groups find that the IP address is not their own and choose not to process the data received from the broadcast. Through this huge network, layer upon layer of mutual broadcast signals, your signal finally arrived in Shanghai.
In fact, at this point, any two computers on earth can establish a connection. The latter protocol layer is mainly for various applications in the computer.
There will be many applications on the computer, and the computer will receive a lot of data, which needs to know which application (process) to distribute the received data to. Different applications (processes) will listen to different port numbers of the system, which produces the transport layer. TCP protocol and UDP protocol belong to the transport layer. The transport layer protocol is embedded in the IP protocol. The IP protocol helps to find the target computer, and the network card finally receives the information, but the network card has to distribute the information. The port number is defined by the transport layer protocol data embedded in IP protocol. After the information reaches the network card of the target computer, the network card will distribute the information to various processes of the computer through the port number of the transport layer protocol.
TCP protocol and UDP protocol belong to the transport layer protocol. The difference between them is that the data of UDP protocol can’t know whether the other party has received it, and every data packet in TCP protocol requires confirmation. If a data loss can’t be confirmed, the sender will resend it.
HTTP protocol based on TCP transport layer belongs to application layer. Data can reach a specific application (process) through the transport layer, but an application will have a variety of functions, such as a browser, which can not only browse web pages, but also write e-mail, download files and watch movies. These various functions, they all need to have their own special data format. For example, web page is mainly HTTP protocol format, file transfer is FTP protocol format, e-mail is SMPT protocol format. Application layer protocol is to help applications (processes) parse the formatted data required by various functions.
Since then, these five layer protocols have helped us to realize various communication and functions of the Internet. The data of these five layer protocols are embedded layer by layer to form a data packet, which is sent and received together. The five layer protocol data in each data packet have their own missions.