[Computer Network] Detailed explanation of Udp

Preface

In the last few articles, we explained the application layer protocols Http and HTTPS. You must know that there are many application layer protocols. These are customized by programmers themselves. When the actual transmission is required, it must be carried out in the transmission layer of the operating system. Today we Let’s learn about the transport layer protocol Udp

identify a communication

To communicate across networks, it is necessary to identify the uniqueness of a network communication

Usually five pieces of information are needed: source IP, destination IP, protocol number, source port number, and destination port number to identify a network communication.

Port division

  • 0-1023
    are well-known port numbers. For widely used application layer protocols such as HTTP, FTP, and SSH, the port numbers are fixed.

    • SSH, using port 22
    • FTP, using port 21
    • telnet, using port 23
    • Http, use port 80
    • HTTPS, using port 443

Well-known port numbers can be viewed using the following command:

cat /etc/services
  • 1024-65535
    The operating system dynamically allocates countermeasure port numbers, and the port number of the client program is randomly assigned from here.

When we design ports, we must avoid these well-known ports.

netstat

It is a tool to check the network status

Options:
- n, refuse to display aliases, digitize if possible
- l, only list the service status in the listening state (listen)
- p, display the name of the program that establishes related links
- t, only display tcp related
- u, only Display udp related
- a, display all options, listen related is not displayed by default

pidof

View process id by process name

Udp protocol end format

Insert image description here

It can be seen that the Udp header length is eight bytes in total. The sixteen-bit Udp length represents the header of the datagram + the total size of the message. If the sixteen-bit checksum is incorrect, the datagram will be discarded directly.

And due to the limitation of the sixteen-bit Udp length, the size that TCP can transmit is limited. The maximum length of data that can be transmitted by a Udp is 64k. If it exceeds, it needs to be manually subpackaged and transmitted multiple times at the application layer, and manually assembled at the receiving end.

Features of Udp

  • No connection, no need to establish a connection, you can transmit if you know the IP and port number
  • Unreliable, no confirmation transmission mechanism, UDP does not return any error message
  • It is datagram-oriented and cannot flexibly control the number and quantity of reading and writing data.
  • Simple.

datagram oriented

No matter how long the application layer hands Udp, Udp will send it directly without splitting or merging it. For example:

If the sender calls sendto and sends 100 bytes, then the receiver must call recvfrom once for 100 bytes. It cannot call recvfrom in a loop, 10 bytes each time.

Udp buffer

Udp does not have a real send buffer. Calling sendto will directly hand over the data to be sent to the kernel, which will transmit the data to the network and perform subsequent actions.

Udp has a receive buffer, but this buffer does not guarantee the order of Udp datagrams. If the buffer is full, it will still be discarded.

Therefore, Udp socket can be written and read, and is full-duplex.

Udp based protocol

  • NFS, network file system
  • TFTP, Simple File Transfer Protocol
  • DHCP, Dynamic Host Configuration Protocol
  • BOOTP, boot protocol
  • DNS, Domain Name Resolution Protocol

Guess you like

Origin blog.csdn.net/m0_73209194/article/details/132273831