Basics of network communication (basic concepts of network communication + TCP/IP model)

1. Basic concepts of network communication

The purpose of network interconnection is network communication, that is, network data transmission. More specifically, it is the transmission of data between different processes in the network host based on the network.

1. LAN & WAN

LAN : Local Area Network, where local indicates that the LAN is a local, locally established private network. Network communication can be easily carried out between hosts in a local area network, also called an intranet;

WAN : Wide Area Network connects multiple local area networks through routers to physically form a large-scale network, forming a wide area network. The LANs within the WAN all belong to its subnets.

The so-called "local area network" and "wide area network" are just the 相对same concepts. If it is a global public wide area network, it is called the Internet (also known as the public network, external network), which is a subset of the wide area network. Sometimes the wide area network referred to in a loose context actually refers to the Internet.

2. IP address

Concept : IP addresses are mainly used to identify the network addresses of network hosts and other network devices (such as routers). Simply put, an IP address is used to locate the network address of a host. Just like when we send express delivery, we need to know the receiving address of the other party so that the courier can deliver the package to the destination.

Format : The IP address is a 32-bit binary number, which is usually divided into 4 "8-bit binary numbers" (that is, 4 bytes), such as: 01100100.00000100.00000101.00000110
. It is commonly expressed in "dotted decimal" format, that is, in the form of abcd (a, b, c, and d are all decimal integers between 0 and 255). For example: 100.4.5.6.

Special IP : The IP address of 127.* is used for local loop back testing. The IP address is 127.0.0.1. The local loop back is mainly used for local-to-local network communication (for the sake of performance, the system will not Transmission via network). For programs that develop network communication (i.e., network programming), the common development method is local-to-local network communication.

3. Port number

Concept : A port number is a numeric identifier used to identify a specific application or service in network communications. During network communication, data is transferred through different port numbers to the correct application or service. Similar to when sending express delivery, you need to specify not only the delivery address (IP address), but also the consignee (port number).

Format : The port number is a number in the range of 0~65535. In network communication, a process can send and receive network data by binding a port number.

Note : Two different processes on the same host cannot bind the same port number, but one process can bind multiple port numbers.

4. Agreement

With the IP address and port number, we can locate the only process in the network, but there is still a problem. Network communication is transmitted based on binary 0/1 data. How to tell the other party what kind of data is sent?

There may be many types of data transmitted in network communication: pictures, videos, texts, etc. The same type of data may have different formats, such as sending a text string "Hello!": How to identify that the data sent is a text type, and what is the encoding format of the text? Based on network data transmission 需要使用协议来规定双方的数据格式.

Concept : Protocol, the abbreviation of network protocol. Network protocol is a set of conventions and rules that all network devices passing through network communication (i.e. network data transmission) must comply with. Such as how to establish a connection, how to identify each other, etc. Only by complying with this agreement can computers communicate with each other. The protocol is ultimately reflected in the format of the data packets transmitted on the network.

5. Default ports for well-known protocols

The system port number range is 0 ~ 65535, of which: 0 ~ 1023 are well-known port numbers. These ports are reserved for server programs to bind widely used 应用层protocols, such as:

  • Port 22: reserved for SSH server binding SSH protocol
  • Port 21: reserved for FTP server binding FTP protocol
  • Port 23: Reserved for Telnet server to bind Telnet protocol
  • Port 80: reserved for HTTP server binding HTTP protocol
  • Port 443: reserved for HTTPS server binding HTTPS protocol

2. TCP/IP five-layer model

1. TCP/IP protocol suite

In network communications, when faced with complex environments, complex protocols need to be agreed upon. The protocol is too complex and can be split into multiple protocols. By classifying the split protocols and layering different categories, the agreement can be reached It defines the calling relationship between levels: the upper-layer protocol is required to call the lower-layer protocol, and the lower-layer protocol provides support for the previous protocol and cannot be called across layers.

Benefits of protocol layering :

  1. Similar to interface-oriented programming: define the interface specification between the two layers, and let both parties follow this specification to connect.
  2. For the user, it does not care how the provider implements it, it only needs to use the interface.
  3. For the provider, using the characteristics of encapsulation, the implementation details are hidden, and only the interface needs to be opened.

The TCP/IP protocol mentioned here is a network protocol suite that contains multiple protocols, includingphysical layerdata link layerNetwork layertransport layerApplication layerWait for multiple levels. These different levels of protocols together constitute a complete network protocol system.

The TCP/IP communication protocol adopts a five-layer hierarchical structure. Each layer calls the network provided by the next layer to complete its own needs:

  • Application layer: The application layer is the top layer of the TCP/IP model and includes various network applications. Its main concern is what the transmitted data will be used for. One of the widely used application layer protocols HTTP and HTTPS.

  • transport layer: Responsible for data transmission between two hosts, without considering the intermediate path, only caring about the starting point and end point, ensuring that data is reliably sent from the source host to the target host. The more common transport layer protocols are TCP and UDP.

  • Network layer: Responsible for address management and routing selection, and path planning between two remote network nodes. For example, in the network layer IP protocol, a host is identified by its IP address, and the data transmission line (routing) between the two hosts is planned through the routing table.

  • data link layer: Responsible for the transmission and identification of data frames between devices, mainly focusing on the transmission between two adjacent nodes. For example, it is transmitted between adjacent nodes through physical addresses (such as MAC addresses). The most typical protocol of the data link layer is the Ethernet protocol.

  • physical layer: Responsible for the transmission method of optical/electrical signals, usually referring to the infrastructure of network communication. Network cables, optical fibers, network interfaces, etc.

2. In the context of protocol layering, how is data transmitted through the network?

The answer is:Encapsulation and decentralization

  1. Encapsulation: When the sender sends data, the data must be handed over to the corresponding layer of protocols from top to bottom for encapsulation.
  2. Decentralization: When the receiver receives the data, it must pass the data to the corresponding layer of protocols from bottom to top for analysis.

(1) Ignore the encapsulation and decentralization of the intermediate forwarding process

Take Li Hua using WeChat to send a message "Hello world" to Xiao Ming as an example. The following is the encapsulation process of messages sent by Li Hua:

  1. First, at the application layer, after the WeChat application on Li Hua's host obtains the above data, it will first use the corresponding application layer protocol to encapsulate the data into application layer data packets.

  2. Then the application layer calls the API provided by the transport layer to process the data. After the transport layer gets the above data, it will use the transport layer protocol to encapsulate the data again. The above figure takes the UDP protocol as an example.

  3. The transport layer calls the network layer. After the network layer gets the UDP packet, it continues to encapsulate it using the network layer protocol. The above figure takes the IP protocol as an example.

  4. The network layer calls the data link layer. After the data link layer gets the IP data packet, it uses the data link layer protocol to encapsulate it. The above figure uses the classic Ethernet protocol as an example:

  5. The data link layer calls the physical layer. After the physical layer gets the Ethernet data frame, it converts the above 0/1 binary data into optical signals, electrical signals, etc. for transmission.

The following is the decentralization process of Xiao Ming receiving messages:

  1. At the physical layer, Xiao Ming's host receives high- and low-level binary signals through the network card, and through signal analysis, it is restored to a binary sequence such as 0/1.

  2. Then the physical layer calls the data link layer, uses the Ethernet protocol to restore the above 0/1 binary data into an Ethernet frame, then removes the frame header and frame tail, takes out the payload of the Ethernet data packet, and submits it upward to the network layer ( There is a field in Ethernet that marks the network layer protocol type).

  3. After the network layer gets the payload, it parses it according to the payload protocol type, here is the IP packet, then removes the IP header, takes out the payload and submits it to the transport layer (there is a field in the IP packet indicating the transport layer protocol type).

  4. The transport layer gets the payload, parses it according to the payload protocol type, here is the UDP packet, removes the UDP header, takes out the payload, and hands it to the application layer according to the port number.

  5. After the WeChat application in the application layer gets the payload, it parses the payload content according to the corresponding application layer program, extracts the corresponding fields, and displays them on the front-end page.

(2) Encapsulation separation in real network environment

Guess you like

Origin blog.csdn.net/LEE180501/article/details/132954686