How do two computers communicate with each other? In a network containing thousands of computers, how does one computer find another computer and send data to it accurately? Today's article will explain how a computer finds another computer in the network and sends data to it through the seven-layer OSI reference model. 1. Physical layer If a computer wants to transmit information to another computer in the network, the first thing to do is to connect the computers, that is, to connect this computer with other computers through optical fiber, cable, twisted pair and other media, so that information can be transmitted. Therefore, the role of the physical layer is actually to connect two computers, and then transmit electrical signals in the form of 0 and 1 between computers at high and low frequencies. 2. Data Link Layer But if there is no uniformly recognized rule for the 0 and 1 signals between computers, the computers cannot interpret them. Therefore, the Ethernet protocol came into being. Figure 1 Bitstream 2.1 Ethernet Protocol In the Ethernet protocol, a data packet consisting of a group of electrical signals is called a frame. In addition, a frame contains two parts: its header and data. Its size is generally 64-1518 bytes, and the bytes of the header part are fixed to 18. Therefore, if the data to be transmitted is large, it is divided into multiple frames for transmission. The header of the frame generally stores some descriptive data, such as the sender, receiver, etc., while the data part stores the specific content to be sent to the receiver. 2.2 MAC address
In the process of sending data from one computer to another computer through the physical layer and link layer, a unique identifier for each computer, the MAC address, is generated to distinguish different computers. Among them, each computer connected to the network has its own network card, and each network card has its own unique address, namely the MAC address. 2.3 Broadcast In a network, computer A is not only connected to computer B, but also to multiple other computers. If computer A knows the MAC address of computer B and wants to send information to computer B, but computer A does not know which route computer B is on, broadcasting occurs. In the same subnet, computer A sends information to computer B. Since the data packet contains the MAC address of computer B (assuming that computer A has learned the MAC address of computer B, the reason will be explained in the ARP protocol in the next section), when sending information, computer A sends it by broadcasting. At this time, after receiving the data packet, computer C or D in the same subnet will take out the MAC address in the data packet and compare it. If it is the same as its own MAC address, it will receive the data packet, otherwise it will discard the data packet. 3. Network layer
In the previous section, we mentioned subnets. In fact, the network we are in is composed of countless subnets, and when broadcasting, only computers in the same subnet can receive it. If there is no subnet division, computer A uses broadcast to send a data packet to computer B. At this time, all computers can receive this data packet, and then start to compare and discard it. However, with so many computers in the network, each receiving the data packet sent by other computers will cause the network to collapse, so subnets are generated. Now the question arises: how can computers distinguish which MAC addresses belong to the same subnet and choose to broadcast and transmit data to each other, and which do not belong to the same subnet and choose to transmit data to the gateway, and then let the gateway forward it. To solve this problem, the IP protocol appeared. 3.1 IP Protocol If the network part of two computers is the same, they are said to be in the same subnet, such as 192.188.88.1 and 192.188.88.2; if their network parts are both 192.188.88 (32 bits in total) and the host parts are the remaining 8 bits, then they are in the same subnet. But how do we know how many bits the network part occupies and how many bits the host part occupies? So the subnet mask was created. The subnet mask and the IP address are both 32-bit binary numbers, but the network part of the subnet mask is all 1 and the host part is all 0. For example, in the previous example, if the network part of the IP address is 24 bits and the host part is 8 bits, then its subnet mask is 11111111.111111111.11111111.00000000, that is, 255.255.255.0. Therefore, after knowing the subnet masks of the two IP addresses, we can determine whether they are in the same subnet. 3.2 ARP Protocol Through the IP addresses and subnet masks of two computers, we can determine whether they are in the same subnet. But how does computer A know the MAC address of computer B? This is where the ARP protocol comes in. The ARP protocol is to send a data packet containing the recipient's IP address to all computers in the same subnet in a broadcast manner. After receiving the data packet, all computers in the subnet will extract the IP address and compare it with their own IP. If they are the same, they will reply with their own MAC address. If they are different, they will discard the data packet. In this way, computer A will know the MAC address of computer B. At the same time, if the IPs of the two computers are not in the same subnet, the computers will send the data packets to the gateway, which will then forward and transmit them. 3.3 DNS Server Another question is, how do we know the IP address of the computer we want to access? Because most of us access the Internet through the network domain name, for example, when accessing China Mobile Lianying Home Smart Platform, we enter the domain name https://open.home.10086.cn/. In fact, when we enter this domain name, the role of the DNS server is to resolve the domain name and then return its corresponding IP to the computer. 4. Transport layer After the physical layer, data link layer, and network layer introduced above, we have successfully transmitted data from computer A to computer B. But how does computer B know which application program it should transmit this data to? At this time, ports appear. In fact, when we transmit data from computer A to computer B, we also need to specify a port for a specific application to process. In other words, the function of the transport layer is to establish port-to-port communication. Sometimes, we don't specify a port when we enter an IP address. In fact, for some specific transmission protocols, most of them have corresponding default ports. For example, the default transmission port for http is 80, and these data will be included in the data packet. In addition, the two most common protocols in the transport layer are TCP and UDP. TCP provides reliable transmission, while UDP provides unreliable transmission. 5. Session Layer Responsible for establishing and maintaining communication between two nodes in the network, and providing interactive session management functions. Common protocols include RPC, SQL, and NFS. The session layer allows two systems to communicate with each other in half-duplex or full-duplex mode, and also allows processes to add synchronization points to data to locate errors and avoid data loss. 6. Presentation Layer Like a "translator" between the application and the network. At the presentation layer, data will be formatted according to the scheme that the network can understand. This format also varies depending on the type of network used. Common protocols include JPEG, ASCII, GIF, DES, and MPEG. At the same time, the presentation layer can also perform compression to reduce the amount of data to be transmitted. 7. Application layer The application layer is located at the seventh layer of the OSI model. Its function is to provide application interfaces for computer users and also directly provide users with various network services. The protocol of this layer defines the interaction rules between application processes and provides services for different network applications through different application layer protocols. For example, the HTTP protocol that supports the World Wide Web and the SMTP protocol used by the email system. In summary, the OSI reference model is divided into 7 layers from top to bottom, namely, application layer, presentation layer, session layer, transport layer, network layer, data link layer and physical layer. In addition, there is a more streamlined TCP/IP reference model, whose structure is divided into 4 layers from top to bottom, namely, application layer, transport layer, network layer and network interface layer. However, the TCP/IP reference model does not subdivide the network interface layer, nor does it make a clear distinction between services and protocols. Therefore, this article explains the principles of computer communication between networks based on the OSI reference model. Author: Wang Xianxin Unit: China Mobile Smart Home Operation Center |
>>: What happens to your body if you eat a clove of garlic every day? Can it really kill bacteria?
In the first half of 2016, the market size of Chi...
Comparing and evaluating speakers is a thankless ...
Research shows that there is more carbon in soil ...
According to foreign media reports, it is no secr...
The giant panda is China's national treasure....
According to foreign media reports, Volkswagen Gr...
Course Catalog 《【Preface】》 .mp4 【Preface】.pdf 01....
The main purpose of push is to promote activation...
Lenovo YOGA 2 13 can be regarded as a popular vers...
Today, the topic is "A couple both got cance...
Every time I post product reviews on skincare, co...
Mobile advertising revenue will reach 31.5 billio...
Source: Xinhuanet...
Guangdiantong is one of Tencent’s two major infor...
This article introduces the product features and ...