UDP : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

UDP
UDP (User Datagram Protocol). This protocol is build on top of IP (Internet Protocol) and allows sending datagrams — messages of arbitrary length (broken into packets). UDP makes no provision for checking that a message was received or retransmitting it. UDP is good when you have a short message coming into the server with a short response. You avoid the overhead of setting up a TCP/IP (Transmission Control Protocol/Internet Protocol) connection and acking every little packet. If the server does not respond, you simply send your packet again. IPv6 (Internet Protocol Version 6) has Jumbograms — giant packets which will make UDP more attractive for high volume server applications. SNTP (Simple Network Time Protocol) is built on top of UDP.

You use the Java classes DatagramPacket and DatagramSocket.

How Does UDP Protocol Work

UDP is similar to IP protocol, except that UDP can deliver bigger payloads that a split over several physical packets. Have a look at the UDP packet header, which is tacked on after the usual IP header. UDP works almost exactly like IP protocol with the minor addition of destination ports.
IP Packet Header
Field Size in bits Purpose
source IP 32 Not in the UDP header, but rather in the basic IP header. Who sent the packet. When it finally arrives at its destination the receiver will know who it was from.
destination IP 32 Not in the UDP header, but rather in the basic IP header. Where the packet is going. On each leg of its journey the routing computer uses this to get the packet a little closer to its final destination.
checksum 16 This is computed as the 16-bit one’s complement of the one’s complement sum of a pseudo header of information from the IP header, the UDP header and the data, padded as needed with zero bytes at the end to make a multiple of two bytes. If the checksum is set to zero, then checksumming is disabled. If the computed checksum is zero, then this field must be set to 0xFFFF.
source port 16 Similar to the function the source port in TCP/IP. It is a free port on the sender’s machine where any responses should be sent.
destination port 16 Which program on the server this should be directed to.
message length 16 total size of UDP header plus data payload (but not the IP header) in 8-bit chunks (aka bytes or octets). The means the maximum size of a packet including data is 64K. This means the payload of data is at most 65,451 bytes. This could have easily been calculated from the length in the IP packet header, but for some reason they duplicated the information.

Everything is in big endian byte order.

Packet Splitting

IP datagrams can hold up to 65535 bytes of payload.

Ethernet frames cannot carry more than 1,500 bytes of payload. So when a UDP packet is transported over an Ethernet LAN (Local Area Network), it may take several Ethernet packets to do it.

IP datagrams larger than the MTU (Maximum Transmission Unit) of the link layer are fragmented and sent in multiple link data units (packets).

UDP datagrams can be up to 65535 bytes long (header + payload). Each UDP datagram maps onto one IP datagram, which is broken into as many fragments as needed by the link layer at each link along the route.

Neither IP nor UDP support retransmission. A dropped or damaged fragment will cause the entire IP datagram and consequently the UDP datagram, to be dropped. UDP does support reassembly of the datagram, however, through the underlying IP datagram support.

In IPv6, it is possible to have jumbograms, datagrams with more than 65,535 bytes.

Gotcha

When you do a DatagramPacket read, you specify the length of the maximum possible incoming packet with setLength(). When a packet comes in, that same field length field is used to tell you how long the packet actually was. You retrieve it with getLength(). You must reset setLength() back to the maximum length to reuse the DatagramPacket, otherwise each successive packet will be chopped smaller and smaller.

TCP/IP vs UDP

You use UDP instead of TCP/IP when:

You use TCP/IP instead of UDP when:

Learning More

Oracle’s Javadoc on DatagramPacket class : available:
Oracle’s Javadoc on DatagramSocket class : available:
book cover recommend book⇒Internetworking with TCP/IP Vol.1: Principles, Protocols and Architecture, fourth editionto book home
by Douglas E. Comer 978-0-13-470188-2 paperback
publisher Prentice Hall 978-0-13-018380-4 hardcover
published 2000-01-18
How IP, UDP and TCP/IP protocols work. How the domain name to IP translation DNS information in propagated.
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.

This page is posted
on the web at:

http://mindprod.com/jgloss/udp.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\udp.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[3.12.161.151]
You are visitor number