UDP protocol of JavaEE-network principle

UDP packet structure

insert image description here

The header size is 8 bytes.

16-bit source port number and 16-bit destination port number:
16 bits can represent 65536 port numbers, which are 0-65535 respectively, of which 1-1023 are dedicated port numbers, which are used to provide services for some well-known servers, for example:

The dedicated port number of the HTTP server is 80
The port number of the FTP file transfer protocol is 21

16-bit length:
Indicates the UDP datagram length, including UDP header and UDP data length. Because the length of the UDP message header is 8 bytes, the minimum value is 8. The
maximum length of the UDP message is about 64KB.
16-bit checksum:
a result is obtained by calculating a certain mathematical formula with the data content as a parameter called checksum.

Since the network transmission is not so stable (it may be disturbed by the external environment), the checksum is used to check whether the data transmission is correct at this time. If the checksum is wrong, it indicates that the data transmission is wrong. If the checksum is correct, it does not prove the transmission. The data must be correct (it belongs to error checking, not checking).

Features of UDP

no connection

If you know the port number and ip address of the other party, you can send data directly without establishing a connection.

Unreliable

There is no security mechanism, just send the datagram, as for whether the receiver receives it, it does not know and will not retransmit.

Datagram Oriented

The application layer gives UDP the length of the message, and UDP sends it as it is, neither splitting nor merging.

buffer zone

UDP only has a receive buffer, not a send buffer.

The popular point is that the data sent by udp will not wait, and will be directly submitted to the system kernel for processing by the kernel, while the receiving buffer is to put the received data into the buffer and be read by the socket object. It should be noted that UDP The order of data received by the receive buffer is not necessarily the same as the order of the data sent, and the data that arrives after the receive buffer is full will be lost.

Application layer protocol based on UDP

NFS: Network File System
TFTP: Simple File Transfer Protocol
DHCP: Dynamic Host Configuration Protocol
BOOTP: Boot Protocol (for diskless device boot)
DNS: Domain Name Resolution Protocol

Guess you like

Origin blog.csdn.net/st200112266/article/details/130172917