Network Communication Study Notes - Basic Knowledge of Computer Networks

1. Basic knowledge of computer network

1. What is a computer network

​ Connect computers distributed in different geographical locations and specialized network equipment with communication lines to form a large-scale and powerful system, so that many computers can easily transfer information to each other, share software, hardware, data information, etc.

A computer network is a collection of many autonomous computers connected by communication lines. It is the product of the combination of computer technology and communication technology.

2. The function of computer network

​ Data communication, resource sharing, improving system reliability, distributed network processing, and load balancing.

3. Composition of computer network

1. Communication subnet

  • Network card: Network interface card or network adapter, it is responsible for sending data to the network, and is also responsible for obtaining data from the network.

  • Cables, repeaters: transmit signals, amplify signals.

  • Switch: It is a device to expand the network, which can provide more connection ports in the sub-network to connect more computers.

  • Router: A router is a hardware device that connects two or more networks. It acts as a gateway between networks. It is a dedicated intelligent network device that reads the address in each data packet and then decides how to transmit it.

It can understand different protocols, such as the Ethernet protocol used by a local area network, and the TCP/IP protocol used by the Internet. In this way, the router can analyze the destination addresses of data packets from various types of networks, convert the addresses of non-TCP/IP networks into TCP/IP addresses, or vice versa; The best route is sent to the designated location.

2. Resource subnet

It consists of networked servers, workstations, shared printers and other devices and related software.

3. Computer network software

Protocol software:

It specifies the guidelines for communication between computers, organized according to the protocol layer model adopted by the network (such as the basic reference model for open system interconnection recommended by ISO). In addition to the physical layer, most of the other layers of protocols are implemented by software.

​ Each layer of protocol software usually consists of one or more processes, and its main task is to complete the functions specified by the corresponding layer protocol, as well as the interface functions with the upper and lower layers.

Network communication software:

​ The main job is to supervise and control the software of communication work, which is the basic component of computer network software. It also allows computers to communicate with other computers.

Communication software generally consists of a line buffer management program, a line control program, and a message management program. The message management program generally consists of five parts: receiving, sending, sending and receiving records, error control, start and end.

Network operating system:

​ The network operating system is a system software used to manage network soft and hard resources and provide simple network management. Common network operating systems include UNIX, Netware, Windows NT, Linux, etc.

Web application software:

​ The main task is to realize various functions stipulated in the overall network plan, and to provide network services and resource sharing. There are general-purpose and special-purpose network application software.

General network application systems are applicable to a wide range of fields and industries, such as data collection systems, data forwarding systems, and database query systems, etc., while dedicated network application systems are only applicable to specific industries and fields, such as bank accounting, railway control, military command, etc. .

4. Classification of computer networks

  • 1. According to the scope and scale of the network

    LAN, MAN, WAN

  • 2. Divided by network communication technology

    broadcast network, point-to-point network

  • 3. Division of transmission media

    Wired network, wireless network, microwave communication, satellite communication

5. The development process of computer network

  • 1. Computer-centric online system

  • 2. The Birth of Packet Switching Networks

  • 3. Network architecture and protocol standardization

    In the 1980s, the ISO organization proposed the open system interconnection reference model OSI. Because this model took care of all parties and interests, it was too large, so no mature products have been launched so far. TCP/IP is a set of protocols that conform to the OSI standard.

  • 4. High-speed computer network 5G, 6G

6. OSI seven-layer network model

​ Network protocols are rules, conventions, and standards formulated for network data exchange. A fully functional computer network needs to formulate a complete set of complex protocol sets. Network protocols are organized in a hierarchical structure. A collection of is called a network architecture.

​ Open System Interconnection Reference Model (English: Open System Interconnection Reference Model, abbreviated as OSI), referred to as OSI model (OSI model), a conceptual model proposed by the International Organization for Standardization, an attempt to make various computers in the world In-Scope Interconnect is the standard framework for networking. OSI divides the computer network architecture (architecture) into the following seven layers:

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-3Jd9fvYX-1666927252832) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028105726631.png)]

Physical layer: Converting data into electronic signals that can be transmitted through physical media is equivalent to porters in the post office.

Data Link Layer: Determines the way to access the network medium, where data is framed and flow control is handled. This layer specifies the topology and provides hardware addressing, which is equivalent to the packing and unpacking workers in the post office.

Network Layer: Right-of-use data routing through a large network is equivalent to sorting workers in a post office.

Transport layer: providing end-to-end reliable connections is equivalent to the delivery staff running the post office in the company.

Session layer: Allowing users to use simple and easy-to-remember names to establish connections is equivalent to a secretary in a company who receives and sends letters, writes envelopes, and opens envelopes.

Presentation layer: Negotiation data exchange format is equivalent to the assistant who briefs the boss and writes letters for the boss in the company.

Application Layer: The interface between the user's application and the network.

7. Four layers of TCP/IP model

​ Now that there is an OSI model standard, why is there still a TCP/IP model? After the OSI model was developed, people found that many levels were too detailed. For example, the upper three levels should be listed. The data in these three levels does not change at all. They only provide interfaces for users and provide an encryption function. , and the functions of some levels are conflicting, or there are some levels that do not need to be so clearly distinguished, so later people integrated the OSI model in the process of using it, and integrated the seven layers into four layers. The TCP/IP model is formed.

As shown below. It merges the upper three layers into the application layer, keeps the transport layer and the network layer unchanged, and then merges the physical layer and the data link layer into the network interface layer. Thus, the 7-layer model is changed into four layers. Of course, the function of the 4-layer model is exactly the same as that of the seven-layer model.

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-EiMXn20V-1666927252833) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028105750838.png)]

**Physical layer: **Responsible for the communication network to send and receive data packets

**Network layer: **Selection, flow control, and network congestion issues, IP protocol is the core of this layer.

**Transport layer: **Enter-to-end connections for sessions are established between machines (for data transmission). The core protocols of this layer are TCP and UDP protocols.

**Application layer:**Mainly provide targeted services for users, the representative protocols of this layer are: HTTP, SMTP, FTP, TELNET.

​ But some people raised objections, thinking that it is possible to merge the upper three layers, but the physical layer and the data link layer cannot be merged, because the functions of these two layers are completely different, so after absorbing everyone's opinions, TCP/ The IP model has also been modified into a five-layer structure, only the upper three layers are merged, and the lower four layers remain unchanged, as shown in the following figure:

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-FbqOQdEQ-1666927252835) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028105903756.png)]

8. MAC address, IP address, domain name, DNS server

MAC address:

​ Also called physical address, the manufacturer of each network card solidifies a 48-bit address (6 bytes, usually expressed as 12 hexadecimal numbers, such as: 00-16-EA-AE-3C-40) , this address is unique in the world, and the switch and router use it to confirm the address of the network device location. The disadvantage is that it is inconvenient to remember and not flexible enough, but it is one of the most important evidences for the Internet police to combat cybercrime.

IP address:

​IP address is based on logic, more flexible, not limited by hardware, easy to remember, and convenient to divide subnets. Therefore, on the surface of computer networks, IP is used for communication. Currently, it consists of 4 integers not exceeding 255. Generally, Expressed in dotted decimal (192.168.2.180). And there is an ARP table in the switch and router, one column records the MAC, and the other records the IP address, and the RARP protocol of the ARP protocol can convert the IP address and the MAC address.

domain name:

​Because it is difficult for ordinary people to memorize a large number of IP addresses, there are texts that replace IP addresses, that is, domain names. For communication between networks, domain names need to be purchased from domain name service providers, and can also be transferred from organizations or individuals.

DNS server:

网络中有一种专门提供翻译域名服务的计算机叫DNS服务器,它负责把域名翻译成IP地址,需要在政 府部分备案并缴纳一些费用才能加入DNS服务器。

2. IP address

1. IPv4 address

The concept of IPv4 addresses was proposed in the early 1980s. Even with newer versions of IP addresses, IPv4 addresses are still the most widely used by Internet users. Composed of 32 binary bits, the IPv4 address is expressed in dotted decimal in daily life, but in the program it is a 32-bit unsigned integer in network byte order.

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-jQqC9CiI-1666927252837) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028110020064.png)]

2. Format of IPv4 address

The first part is the network bit, indicating the network segment to which the IP address belongs

The second part is the host bit, which is used to uniquely identify a certain network device on this network segment

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-mb8NVbZ4-1666927252840) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028110045826.png)]

​ The host bit is all 0, indicating a network segment, which cannot be assigned to network devices. The host bit is all 1, which is a broadcast address and is owned by a switch or router. Other IP addresses except network addresses and broadcast addresses can be used as The IP address of the network device.

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-hyKt0VY6-1666927252842) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028110100688.png)]

3. Classification of IPv4 addresses

​ According to the official IP address allocation scheme, the performance of early equipment was insufficient. This IP address classification scheme can improve the forwarding efficiency of equipment.

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-kN20RBLV-1666927252844) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028110118631.png)]

​ **Type A address: **The first 8 bits are the network address, and the last 24 bits are the host address. The first bit of the network bit must be 0, so the length of the network ID in this type of IP address is 8 bits, and the length of the host ID It is 24 bits, and the range of this type of IP address is 1.0.0.0~126.255.255.255, which is generally used in wide area network.

​ **Class B address: **The first 16 bits are the network address, and the last 16 bits are the host address. The first 2 bits of the network bit must be 10, because the length of the network ID in this type of IP address is 16 bits, and the length of the host ID is 16 bits. The range of this type of IP address is 128.0.0.0~191.255.255.255. LAN.

​ **Class C address: **The first 24 bits are the network address, and the last 8 bits are the host address. The first 3 bits of the network bit must be 110, so the length of the network ID in this type of IP address is 24 bits, and the length of the host is 8 bits. This type of IP address ranges from 192.0.0.0 to 223.255.255.255 and is generally used in LAN.

​ **Class D address:** The first byte of this type of IP address starts with 1110, which is a specially reserved address and does not point to a specific network. This type of IP address is currently used in multicast, and its address range is 224.0.0.0~239.255.255.255.

​ **Class E address:**This type of IP address starts with 11110, which is a reserved address. Its address range is 240.0.0.0~255.255.255.254

4. Special IPv4 address

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-JHJXIqc2-1666927252847) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028110223089.png)]

5. Public network IPv4 address and private network IPv4 address

​ The public network refers to the Internet. The public network address is the IPv4 address that can be routed on the Internet (accessed by other devices), and the private network address cannot be routed on the public network. IPv4 address.

​ Now, the total number of IP addresses required by all terminal systems and network devices in the world has exceeded the maximum number of addresses supported by 32-bit IPv4 addresses of 4,294,967,296. In order to save IPv4 addresses, some of the IP addresses in IPv4 are officially reserved for private network addresses , Class A, B, and C address segments all reserve specific ranges of addresses as private network addresses, assigning private network addresses to hosts saves public network addresses, which can be used to alleviate the problem of IP address shortage.

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-zmzF39Ga-1666927252848) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028110248292.png)]

​ Private network addresses are commonly used in enterprise networks, and private network addresses in different enterprise networks can overlap. By default, hosts in the network cannot use private network addresses to communicate with the public network. We can access the Internet only by ISP organizations. However, this kind of IP address is generally not for individuals, but for a unit and a region (shared broadband).

​ That is to say, what we actually have access to are generally private network addresses, that is, we use the ipconig command to find all private addresses, which is equivalent to the IP address in the LAN. When we really connect to the Internet, we will first set the The data is sent to the router, and then processed by the router to realize the real network operation. The address of the router is the IP address of the real network, which is the public network IP, and all we find on our computers are private network IPs.

6. Subnet mask

​ The format is the same as that of an IPv4 address, but the difference is that its network bits are all 1, and the host bits are all 0. It is mainly used in private networks. IPv4 addresses and subnet masks can be used to uniquely identify a network segment A network device in .

category Binary data for subnet mask Decimal data for the subnet mask
A 11111111 00000000 00000000 00000000 255.0.0.0
B 11111111 11111111 00000000 00000000 255.255.0.0
C 11111111 11111111 11111111 00000000 255.255.255.0

​ The subnet mask tells the router which part of the address is the network address and which part is the host address, so that the router can correctly determine whether any IP address belongs to this network segment, so as to perform routing correctly.

​ Subnet mask & ip address = network address, if the network addresses of the two ip addresses are the same, it means that they are in the same subnet, and they can communicate directly without a router. On the contrary, if the network of two ip addresses If the addresses are different, a router needs to be used for cross-network communication, and the IPv4 addresses in different subnets can be the same.

​ The subnet mask is a virtual IP technology created to solve IP address allocation under the background of shortage of IPv4 address resources. Through the subnet mask, the three types of addresses A, B, and C are divided into several subnets, thereby significantly improving The efficiency of IP address allocation effectively solves the shortage of IP address resources. On the other hand, in order to better manage the network in the enterprise intranet, network administrators also use the role of subnet masks to artificially divide a larger enterprise intranet into more small-scale subnets, and then use The routing function of the three-layer switch realizes the interconnection of subnets, thus effectively solving many network management problems such as network broadcast storms and network viruses.

7. Gateway address

​ The computer responsible for the egress in the private network, the computer will send the data to be sent to the gateway address first, and it will be responsible for forwarding, usually by a router (a router is a computer with routing function).

8. IPv6 address

​ The number of IPv4 address combinations is limited, and in total, 4 billion (256 4) unique addresses can be calculated. This number never seems to expire when IPv4 addresses just started. However, things are different now. In 2011, the Internet Assigned Numbers Authority (IANA) distributed the last chunk of the IPv4 address space. In 2015, IANA officially announced that the United States had run out of IPv4 addresses.

To this day, IPv4 addresses still carry the most (over 90%) of Internet traffic. So far, there are ways to continue using IPv4 addresses even though there is currently an issue of IPv4 address exhaustion. For example, Network Address Translation (NAT) is one approach when only one unique IP address is required to represent a group of devices. Besides that, IP addresses can be reused.

Of course, we already have a completely exhausted solution - IPv6 addresses, which use colon-separated hexadecimal numbers. It is divided into eight 16-bit blocks, forming a 128-bit address scheme.

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-AlPrMULp-1666927252849) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028110556993.png)]

​ Look closely and you will see that IPv6 addresses are not a completely new technology. It is the latest version of the Internet Protocol, but it was developed in 1998 to replace IPv4 addresses.

9. The difference between IPv4 and IPv6

Address type:

IPv4 has three different types of addresses: multicast, broadcast, and unicast. IPv6 also has three different types of addresses: anycast, unicast, and multicast.

Packet size:

​ For IPv4, the minimum packet size is 576 bytes. For IPv6, the minimum packet size is 1208 bytes.

The number of fields in the header area:

IPv4 has 12 header fields while IPv6 supports 8 header fields.

Optional fields:

IPv4 has optional fields, while IPv6 does not. However, IPv6 has extension headers that allow the protocol to be extended in the future without affecting the main packet structure.

Configuration:

In IPv4, newly installed systems must be configured to communicate with other systems. In IPv6, configuration is optional, which allows selection based on desired functionality.

safety:

In IPv4, security mainly depends on websites and applications. It is not an IP protocol developed for security. IPv6 integrates the Internet Protocol Security Standard (IPSec). Unlike IPv4, the network security of IPv6 is optional, and the network security items in IPv6 are mandatory.

Compatibility with mobile devices:

IPv4 is not suitable for mobile networks because, as we mentioned earlier, it uses dotted decimal notation, while IPv6 uses colons and is a better choice for mobile devices.

The main function:

IPv6 allows direct addressing because of the large number of possible addresses. However, IPv4 is widely spread and supported by many devices, which makes it easier to use.

10. Which one to use for IPv4 or IPv6

There is no standard answer to the question of whether to use IPv6 or IPv4. IPv6 addresses are critical when considering future network experiences. There are other ways to use IPv4 addresses even when we don't have network addresses anymore, but these options may slightly affect network speed or cause other problems. However, the use of IPv6 requires the development of new technologies and products that support IPv6. IPv6 is obviously not faster than IPv4, but a complete change from IPv4 to IPv6 will give the Internet a larger pool of unique IPs. So why are we still using IPv4?

The problem is that IPv4 and IPv6 cannot communicate with each other. This is why the integration and adaptation of IPv6 is complex. Most websites or applications only support IPv4 type IP addresses. Imagine suddenly changing the IP address of each device. Users won't be able to access most websites or applications, and we'll be left in total chaos on the internet. The process of converting from an old IP type to a new IP type should be done step by step. For example, the two protocols can run in parallel. This feature is called dual stacking. It allows users to access both IPv4 and IPv6 content.

3. TCP protocol and UDP protocol

1. What are TCP/IP, TCP, and UDP

The TCP/IP protocol is a protocol cluster, which includes many protocols, and UDP is only one of them. The reason why it is named TCP/IP protocol is because TCP and IP protocols are two very important protocols, so they are named after them. TCP and UDP are two protocols located in the transport layer of the TCP/IP model, and they represent the two communication modes of the TCP/IP model.

​TCP (Transmission Control Protocol) transmission control protocol, also known as data flow protocol.

​ UDP (User Datagram Protocol) User Datagram Protocol, also called message protocol.

2. Introduction to TCP protocol

​TCP is a wide area network-oriented communication protocol, the purpose of which is to provide a safe and reliable communication method between two communication endpoints when communicating across multiple networks:

The main features of TCP:

  • flow-based approach

  • Connection-oriented;

  • reliable means of communication;

  • When the network condition is not good, try to reduce the bandwidth overhead of the system due to retransmission;

  • Communication connection maintenance is oriented to the two endpoints of communication, regardless of intermediate network segments and nodes.

TCP transmission mechanism:

​ **Data Fragmentation:** Fragmentation of user data at the sending end, reorganization at the receiving end, TCP determines the size of the fragmentation and controls fragmentation and reassembly;

​ **Arrival Confirmation:** When the receiving end receives the fragmented data, it sends an acknowledgment to the sending end according to the serial number of the fragmented data;

​ **Timeout retransmission: **The sender starts the timeout timer when sending the fragment, if the corresponding confirmation is not received after the timer expires, the fragment is resent;

​ **Sliding window: **The receiving buffer space of each party in the TCP connection is fixed. The receiving end only allows the other end to send the data that the receiving end buffer can accept. TCP provides flow control on the basis of the sliding window to prevent large A fast host overflows the buffer of a slower host;

​ **Out-of-order processing: **TCP fragments transmitted as IP datagrams may be out of order when they arrive. TCP will reorder the received data and deliver the received data to the application layer in the correct order;

​ **Duplicate processing: **TCP fragments transmitted as IP datagrams will be repeated, and the receiving end of TCP must discard the repeated data;

​ **Data checksum:**TCP will maintain the checksum of its header and data, which is an end-to-end checksum to detect any changes in the data during transmission. If there is an error in the checksum of the received fragment, TCP will discard the fragment, and does not confirm receipt of the segment, causing the peer to time out and resend.

TCP header format:

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-abzG1SDc-1666927252850) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028111019798.png)]

Source Port 是源端口,16位。
Destination Port是目的端口,16位。
Sequence Number是发送数据包中的第一个字节的序列号,32位。
Acknowledgment Number是确认序列号,32位。
Data Offset是数据偏移,4位,该字段的值是TCP首部(包括选项)长度除以4。
标志位: 6位
    URG表示Urgent Pointer字段有意义:
    ACK表示Acknowledgment Number字段有意义
    PSH表示Push功能,RST表示复位TCP连接
    SYN表示SYN报文(在建立TCP连接的时候使用)
    FIN表示没有数据需要发送了(在关闭TCP连接的时候使用)
    Window表示接收缓冲区的空闲空间,16位,用来告诉TCP连接对端自己能够接收的最大数据长度。
Checksum是校验和,16位。
Urgent Pointers是紧急指针,16位,只有URG标志位被设置时该字段才有意义,表示紧急数据相对序列号
(Sequence Number字段的值)的偏移。

3. TCP connection process

​TCP is the transport layer protocol in the Internet, which uses the three-way handshake protocol to establish a connection. When the active party sends a SYN connection request, it waits for the other party to reply SYN+ACK, and finally executes ACK confirmation for the other party's SYN. This method of establishing a connection can prevent erroneous connections. The flow control protocol used by TCP is a variable-size sliding window protocol.

​ Establishing a connection requires a three-way handshake, and terminating a connection requires a four-way handshake, which is caused by TCP's half-close.

The process of TCP three-way handshake:

  1. The client sends a SYN (SEQ=x) message to the server and enters the SYN_SEND state.

  2. The server receives the SYN message, responds with a SYN (SEQ=y) ACK (ACK=x+1) message, and enters the SYN_RECV state.

  3. The client receives the SYN message from the server, responds with an ACK (ACK=y+1) message, and enters the Established state.

    The three-way handshake is completed, the TCP client and server successfully establish a connection, and data transmission can begin.

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-epZDA8Wf-1666927252854) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028111319328.png)]

The process of TCP waving four times:

  1. An application process first calls close, saying that the end performs an "active close". The TCP at that end then sends a FIN segment, indicating that the data has been sent.
  2. The peer receiving this FIN performs a "passive close" (passive close), and this FIN is confirmed by TCP. Note: The reception of FIN is also passed to the receiving application process as an end-of-file, after any other data that has been queued for the application process to receive, because the reception of FIN means that the receiving application process The process has no additional data to receive on the corresponding connection.
  3. After some time, the application process that receives this end-of-file will call close to close its socket. This causes its TCP to also send a FIN.
  4. The original sender TCP that received the final FIN (that is, the end that performed the active close) acknowledges the FIN. [3] Since each direction requires a FIN and an ACK, it usually requires 4 segments, so it is called four waves.

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-RkLG78gw-1666927252855) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028111349447.png)]

Notice:

  1. "Usually" means that in some cases, the FIN of step 1 is sent together with the data. In addition, the sections sent in steps 2 and 3 are all from the end that performs passive closing, and may be merged into one section.
  2. Between steps 2 and 3, it is possible to flow data from the side where the passive close is performed to the side where the active close is performed, which is called a "half-close".
  3. When a Unix process terminates, either voluntarily (by calling exit or returning from main) or involuntarily (by receiving a signal that terminates the process), all open descriptors are closed, causing any TCP A FIN is also issued on the connection.
  4. Either client or server can perform an active shutdown. Typically, the client performs an active close, but some protocols, such as HTTP/1.0, have the server perform an active close.

4. Introduction to UDP protocol

​ It is a transmission protocol that supports connectionless. The UDP protocol is used to process data packets like the TCP protocol. In the OSI model, both are located at the transport layer, which is on the upper layer of the IP protocol. It is complementary to TCP. UDP Provides a way for applications to send encapsulated IP packets without establishing a connection.

​Since the transmission of data does not establish a connection, there is no need to maintain the connection state, including the state of sending and receiving, etc., so one server can transmit the same message to multiple clients at the same time (many-to-many communication).

The main features of UDP:

​ UDP does almost nothing special except for sending packets to applications and allowing them to structure their own protocols at the desired level, while the TCP protocol does almost everything that a communication protocol should do.

​ UDP does not provide the disadvantages of packet grouping, assembly, and inability to sort data packets. That is to say, after a packet is sent, it is impossible to know whether it has arrived safely and completely.

UDP header format:

The header of the UDP packet is very short, only 8 bytes. Compared with the 20-byte packet of TCP, the additional overhead of UDP is very small.

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-RhGpP03N-1666927252857) (C:\Users\AllureLove1231\AppData\Roaming\Typora\typora-user-images\ image-20221028111529733.png)]

Length:

The length of a datagram refers to the total number of bytes including header and data. Because the length of the header is fixed, this field is mainly used to calculate the variable length data part (also known as the data payload).

The maximum length of a datagram varies depending on the operating environment. Theoretically, the maximum length of a datagram including the header is 65535 bytes. However, some practical applications tend to limit the size of the datagram, sometimes down to 8192 bytes.

​ Throughput is not regulated by the congestion control algorithm, but only limited by the data rate generated by the application software, the transmission bandwidth, and the performance of the source and end hosts.

UDP is packet-oriented. The sender’s UDP sends the message to the application, after adding the header, it is delivered to the IP layer. It is neither split nor merged, but the boundary of these messages is reserved, and the application needs to choose the appropriate one. Packet size.

Checksum:

The UDP protocol uses the checksum value in the header to ensure data security. The check value is first calculated by a special algorithm at the data sender, and needs to be recalculated after being passed to the receiver.

​ If a datagram is tampered with by a third party during transmission or damaged due to line noise, etc., the check calculation values ​​of the sender and receiver will not match, so the UDP protocol can detect whether there is an error. This is different from the TCP protocol, which requires a checksum value.

The scope of application of UDP:

​ It is mainly used in the transmission that does not require the arrival of packets in sequence. The inspection and sorting of the packet transmission sequence is completed by the application layer, that is, the reliability is taken care of by the application layer. The UDP protocol is suitable for multiple applications running on the same device. Communication, even network communication is only suitable for transmitting a small amount of data at a time, using UDP protocols including: TFTP, SNMP, NFS, DNS, BOOTP.

​ UDP packets do not have reliability guarantees, sequence guarantees, and flow control fields, etc., and their reliability is poor. However, because the UDP protocol has fewer control options, the delay in the data transmission process is small, and the data transmission efficiency is high. It is suitable for applications that do not require high reliability, or applications that can guarantee reliability.

​ Multimedia data flow does not generate any additional data, and does not retransmit even if it is known that there is a damaged packet. When emphasizing transmission performance rather than transmission integrity, such as: audio and multimedia applications, UDP is the best choice. UDP is also a good choice when the data transmission time is so short that the previous connection process becomes the main body of the entire traffic.

5. Choose TCP or UDP

TCP provides connection-oriented and reliable services to the upper layer, and UDP provides connectionless and unreliable services to the upper layer. Although UDP is not as accurate as TCP transmission, it can also make a difference in many places with high real-time requirements.

UDP TCP
Is it connected no connection connection-oriented
Is it reliable Unreliable transmission, no use of flow control and congestion control Reliable transmission, using flow control and congestion control
Number of connection objects Support one-to-one, one-to-many, many-to-one and many-to-many interactive communication Only one-to-one communication
transfer method message-oriented stream-oriented
head overhead The header overhead is small, only 8 bytes The minimum of the header is 20 bytes, and the maximum is 60 bytes
scenes to be used Is for real-time applications (IP telephony, video conferencing, live broadcast, etc.) Suitable for applications requiring reliable transmission

Connection | Connection-oriented |
| Reliable | Unreliable transmission, no flow control and congestion control | Reliable transmission, use flow control and congestion control | |
Number of connection objects | Support one-to-one, one-to-many, many-to-one and Many-to-many interactive communication | Can only be one-to-one communication |
| Transmission method | Packet-oriented | Byte-oriented |
| Header overhead | Header overhead is small, only 8 bytes | |
| Usage Scenario| is used for real-time applications (IP telephony, video conferencing, live broadcast, etc.) | suitable for applications requiring reliable transmission|

Guess you like

Origin blog.csdn.net/m0_62480610/article/details/127568256