Article Directory
Characteristics of UDP, UDP packets and error detection structure
A, UDP characteristics
You can answer why so many applications to select UDP.
UDP is a connectionless protocol for transmitting data and does not require a server connection, only need to know the socket ip and listening port, no link without a purpose, just out of the datagram delivery, regardless of whether the recipient has successfully received, a unreliable transport.
1. do not need to establish a connection
- As we all know, TCP need to go through three-way handshake before data transmission , UDP does not need to do anything to prepare for data transmission, UDP does not introduce delay in establishing the connection.
- This is the main reason over UDP instead of TCP DNS operation.
- The reason for using the HTTP protocol TCP, because for the HTTP protocol, the reliability is essential.
2. No connection status
- Need to maintain TCP connection status . This connection state includes receive and transmit buffers, congestion control parameters, and the sequence and acknowledgment number parameters. (Later if you have time, will detail under TCP congestion control program, and the program, the state information are necessary)
- The UDP does not need to maintain the connection status, they do not track these parameters
3. The packet header overhead small
Each segment has a 20-byte TCP packet header overhead, while UDP is only 8 bytes of overhead
So, if not necessary, such as e-mail, remote terminal services, web, and file transfer, you need reliable data transmission, it will go to the use of TCP. The rest of especially high real-time requirements of applications such as real-time video conferencing, Internet telephony, the general would prefer to use UDP
About when to send what data the more sophisticated application-layer control
as long as the application to pass data to the UDP, UDP this data will be packaged into a UDP segment and immediately passed to the network layer.
And there is the TCP congestion control mechanisms to ensure the safe transfer of data, regardless of how much time success and reliable transmission needed.
Therefore, some real-time applications, such as micro-channel video, voice and data are more timely want to send, for which part of the data loss can be tolerated, more suitable for use UDP
Two, UDP packet structure
The application layer data occupies the data field of the UDP segment. UDP header only four fields, each field consists of 2 bytes, i.e., only 8 byte UDP header.
-
Port Number: The destination host can run the application data to the destination end of the respective process system, perform demultiplexing functions.
-
Length: This field indicates the number (header + data) bytes in a UDP packet segment
-
And testing: The receiver uses the checksum to check whether there is a packet error period, i.e., error detection.
Third, multiplexing, demultiplexing
Four, UDP error detection
UDP checksum provides error detection function.
Testing and for determining when the equivalent UDP packet reaches the destination mobile segments from a source, wherein the changed whether bit (for example, due to link interference or noise introduced problems when stored in the router).
UDP sender of all 16 bit words of the packets and segments 反码
operation, any spillage encountered summation are rolled back. The results obtained are placed in UDP packets in the segment checksum field.
1. Examples
Assuming the following three 16 bit words:
These two 16-bit words before the sum is:
And then added to the third 16-bit words, stars:
It found overflowed, and the volume will be back, that is the first place to add 1 to the last digit yields:
Then subjected to anti-arithmetic code, a so-called anti-code operation, all that is changed to a 1 into 0,0
This is the results of tests and. And added together at the receiving side, all of the four 16-bit words (including the checksum). If the packet does not introduce errors, and apparently will be received at the 1111111111111111. And if one of these bits is 0, then we know that the packet error has occurred.
In the end, based on UDP provides error detection at the transport layer, which is the end to end principle in the system design to be blessed
and UDP, while providing error detection, error recovery, but it could do nothing. That's where reliable data transmission -TCP, and
of course, if that is not TCP, then will supplement the deficiencies of UDP in the session layer