UDP User Datagram Protocol
User Datagram Protocol (UDP) UDP is the protocol available to network programmers who wish to send datagrams UDP datagrams are called user datagrams, since they allow user-level creation & transmission of datagrams Other IP datagrams are used for implementation of connection-based transport (TCP), error control (ICMP), or inter-router communication (BGP, RIP, OSPF) UDP has a small, fixed-size (8 byte) header
Connectionless Service In connectionless service, a host just sends packets No connection needs to be established No virtual circuit needs to be created A connectionless socket can send messages to multiple recipients
UDP Applications UDP can be used for: Instant messaging (e.g. ICQ) Multicast messaging UDP is best suited for applications which have: Sporadic messaging Long periods of delay between messages
User Datagrams BytesNameDescription 2Source PortThe port used to send the message 2Dest. PortThe port to be used to receive the message 2LengthThe length of the data in the message 2ChecksumThe checksum of the message data ?DataThe data of the message 8 bytes
Ports Ports represent portals where information may be transmitted or received by a network-enabled machine One port may be used to send ICQ messages to other ICQ users Another port may be used to send requests to mail servers (such as SMTP servers) Without ports, messages from the SMTP server or an ICQ user will be indistinguishable
Ports It is important to note (and often overlooked) that all datagrams contain 2 ports: One for the source The port that was used to send the message One for the destination The port that was used to receive the message
Ports Some ports were associated with specific network functions to make port numbers unnecessary in those domains: 25: SMTP (used for sending ) 80: HTTP (used for handling web requests) 90: SHTTP (used for handling secure web requests) Some others are listed on p.205 & p.244 These reserved ports are both UDP and TCP ports
Ports M2 80 Web 25 SMTP 8080 Tomcat M1 Web 80 Web 90 ICQ ICQ Ext Ext 16403
User Datagrams UDP datagrams are encapsulated inside IP datagrams The normal IP headers are present The data portion of the IP datagram contains the UDP headers (port numbers, etc.) and the message data
UDP Message Encapsulation User DataUDP Header IP DataIP Header Frame DataFrame Header Network Frame
UDP Layering Application User Datagram Protocol (UDP) Internet Protocol (IP) Network Interface Hardware
UDP Programming // in Java DatagramSocket socket = new DatagramSocket(16789); String msg = "hello"; String IP = " "; InetAddress address = InetAddress.getByName(IP); DatagramPacket outputPacket = new DatagramPacket(msg.getBytes(), msg.length(), address, 12465); socket.send(outputPacket);
UDP Programming // in Java DatagramSocket socket = new DatagramSocket(16789); byte[] data = byte[256]; DatagramPacket inputPacket = new DatagramPacket(data, 256); socket.receive(inputPacket);
UDP Summary UDP is a transport-level protocol Which means that UDP deals with message delivery UDP is a connectionless protocol built on top of IP, which is already connectionless Therefore, UDP is essentially direct IP datagram transmission UDP does not provide a reliable service UDP uses ‘best effort’ delivery If messages do not arrive, the application layer (i.e. the application itself) must determine if and when to retransmit the message