UDP message structure

Table of contents

1. port

2. Message length

3. Checksum


UDP is one of the network protocols at the transport layer. The best way to learn a protocol is to understand the message format of this protocol. That is, how to organize this data.

The following figure shows the format of a UDP datagram: 

 

 


1. port

  • source port and destination port.

The source IP and source port indicate where the data comes from, and the destination IP and destination port indicate where the data is going.

Next, let’s take an example to understand them better : Xiaocao came from Chongqing and traveled to Luoyang. At this time, Xiaocao is the source port , and tourism is the destination port . Chongqing is the source IP , and Luoyang is the destination IP .

  • The port number

Each port number occupies 2 bytes in the UDP message, and the value range is 0-65535 (2^16-1).

Note: Port numbers <1024[1-1023] are well-known port numbers, which should not be used under normal circumstances. For example (http:80).


 

2. Message length

The maximum length of a UDP message is 64KB

We all know that 64KB is really small for the current program. Since it is so small, why can't it be expanded?

There are two reasons for this:

1. If you want to expand, it means to upgrade, then you must upgrade the hosts all over the world, otherwise you will not be able to interact because of incompatible versions. The cost is very high;

2. There are different host operating systems all over the world, such as windows, linux, mac, etc.

 


3. Checksum

The network transmission is unstable, and errors may occur. For example: the network cable transmits electrical signals (high and low levels). Due to the interference of the magnetic field, low -> high, high -> low (bit flip), it will cause very serious consequences.

Then, in order to avoid this consequence, we introduce a checksum to check whether the transmitted data is wrong.

Example 1:

Dr. Gu asked Xiaoyu to buy vegetables at noon. There were tomatoes, eggs, shredded potatoes, and green peppers. He told Xiaoyu that there were four kinds of vegetables in total, so don’t miss out!!!

So Xiaoyu came to the vegetable market. When Xiaoyu walked around and was about to go home, he checked and found that he only bought three kinds of vegetables, so he went to buy the missing ones!!!

However, there is a problem with the above!!! The checksum cannot be verified, it can only be falsified. It is impossible to be sure that the four dishes bought are correct. Only when the three dishes are bought, the quantity is found to be wrong.

Therefore, in order to have a higher verification and recognition rate, the data content is usually used as a parameter for calculation.

Example 2:

KFC has a set meal (Orleans Chicken Leg Burger + Medium Cup of Coke + Medium French Fries); the front desk told the kitchen staff according to the order, an Aobao, Zhongke, and Medium Potatoes (this is based on the data content as the checksum). When serving, match the content on the list and write it off.


  • process

1. The sender substitutes the payload data into the checksum algorithm, and the calculated result is recorded as sum1;

2. The sender sends the entire string of data above to the receiver; (the data received by the receiver has both payload and checksum sum1)

3. When the receiver receives this string of data, it calculates the payload again according to the checksum algorithm, and obtains the result sum2;

4. Compare whether sum1 and sum2 are the same.

If it is different, there must be a problem with the data.


total

I wish you all the best and good health, see you next time!!!

Guess you like

Origin blog.csdn.net/m0_71690645/article/details/130092223