Java Reference
In-Depth Information
CHAPTER 12
UDP
Previous chapters discussed network applications that run on top of the TCP transport
layer protocol. TCP is designed for reliable transmission of data. If data is lost or dam‐
aged in transmission, TCP ensures that the data is resent. If packets of data arrive out
of order, TCP puts them back in the correct order. If the data is coming too fast for the
connection, TCP throttles the speed back so that packets won't be lost. A program never
needs to worry about receiving data that is out of order or incorrect. However, this
reliability comes at a price. That price is speed. Establishing and tearing down TCP
connections can take a fair amount of time, particularly for protocols such as HTTP,
which tend to require many short transmissions.
The User Datagram Protocol (UDP) is an alternative transport layer protocol for send‐
ing data over IP that is very quick, but not reliable. When you send UDP data, you have
no way of knowing whether it arrived, much less whether different pieces of data arrived
in the order in which you sent them. However, the pieces that do arrive generally arrive
quickly.
The UDP Protocol
The obvious question to ask is why anyone would ever use an unreliable protocol. Surely,
if you have data worth sending, you care about whether the data arrives correctly?
Clearly, UDP isn't a good match for applications like FTP that require reliable trans‐
mission of data over potentially unreliable networks. However, there are many kinds of
applications in which raw speed is more important than getting every bit right. For
example, in real-time audio or video, lost or swapped packets of data simply appear as
static. Static is tolerable, but awkward pauses in the audio stream, when TCP requests
a retransmission or waits for a wayward packet to arrive, are unacceptable. In other
applications, reliability tests can be implemented in the application layer. For example,
if a client sends a short UDP request to a server, it may assume that the packet is lost if
no response is returned within an established period of time; this is one way the Domain
 
Search WWH ::




Custom Search