UDP -- like its cousin the Transmission Control Protocol
(TCP) -- sits directly on top of the base Internet Protocol (IP). In general,
UDP implements a fairly "lightweight" layer above the Internet
Protocol. It seems at first site that similar service is provided by both UDP
and IP, namely transfer of data.But we need UDP for multiplexing/de-multiplexing
of addresses.
UDP's main purpose is to abstract network traffic in the form of data-grams.
A data-gram comprises one single "unit" of binary data; the first
eight (8) bytes of a data-gram contain the header information and the remaining
bytes contain the data itself. UDP Headers
The UDP header consists of four (4) fields of two bytes each:
|
Source
Port
|
Destination Port
|
|
length
|
Checksum
|
·
source port number
·
destination port number
·
data-gram size
·
check-sum
UDP port numbers allow different applications to maintain their own "channels" for data; both UDP and TCP use this mechanism to support multiple applications sending and receiving data concurrently. The sending application (that could be a client or a server) sends UDP data-grams through the source port, and the recipient of the packet accepts this data-gram through the destination port. Some applications use static port numbers that are reserved for or registered to the application. Other applications use dynamic (unregistered) port numbers. Because the UDP port headers are two bytes long, valid port numbers range from 0 to 65535; by convention, values above 49151 represent dynamic ports.
The data-gram size is a simple count of the number of bytes contained in the header and data sections . Because the header length is a fixed size, this field essentially refers to the length of the variable-sized data portion (sometimes called the payload). The maximum size of a data-gram varies depending on the operating environment. With a two-byte size field, the theoretical maximum size is 65535 bytes. However, some implementations of UDP restrict the data-gram to a smaller number -- sometimes as low as 8192 bytes.
UDP check-sums work as a safety feature. The check-sum value represents an encoding of the data-gram data that is calculated first by the sender and later by the receiver. Should an individual data-gram be tampered with (due to a hacker) or get corrupted during transmission (due to line noise, for example), the calculations of the sender and receiver will not match, and the UDP protocol will detect this error. The algorithm is not fool-proof, but it is effective in many cases. In UDP, check summing is optional -- turning it off squeezes a little extra performance from the system -- as opposed to TCP where check-sums are mandatory. It should be remembered that check summing is optional only for the sender, not the receiver. If the sender has used check-sum then it is mandatory for the receiver to do so.
Usage of the Check-sum in UDP is optional. In case the sender does not use it, it sets the check-sum field to all 0's. Now if the sender computes the check-sum then the recipient must also compute the check-sum an set the field accordingly. If the check-sum is calculated and turns out to be all 1's then the sender sends all 1's instead of all 0's. This is since in the algorithm for check-sum computation used by UDP, a check-sum of all 1's if equivalent to a check-sum of all 0's. Now the check-sum field is unambiguous for the recipient, if it is all 0's then check-sum has not been used, in any other case the check-sum has to be computed.
No comments:
Post a Comment