0% found this document useful (0 votes)
10 views31 pages

INF 123 Lecture 4

The document describes the User Datagram Protocol (UDP). UDP is a connectionless transport protocol that can be used as an alternative to TCP. UDP uses datagrams to send data from one computer to another without establishing a connection. UDP does not provide reliability, flow control, or ordered delivery.

Uploaded by

Tzar Umang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views31 pages

INF 123 Lecture 4

The document describes the User Datagram Protocol (UDP). UDP is a connectionless transport protocol that can be used as an alternative to TCP. UDP uses datagrams to send data from one computer to another without establishing a connection. UDP does not provide reliability, flow control, or ordered delivery.

Uploaded by

Tzar Umang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 31

USER DATAGRAM

PROTOCOL (UDP)
Prof. Crista Lopes
What is UDP?
 an unreliable transport protocol that can be used in
the Internet.
 an alternative to the Transmission Control
Protocol(TCP).
 UDP uses the Internet Protocol to get a data unit
(datagram) from one computer to another.
 a connectionless transport layer protocol in the
TCP/IP protocol stack.
Position of UDP in the OSI model
UDP(cont’d)
 UDP does not provide:
 flow or error control
 connection management
 guaranteed in-order packet delivery
 UDP is almost a “null” transport layer.
 UDP is often used for time-sensitive applications
where missing data is preferred to late-arriving
data.(i.e. Domain Name Server (DNS))
Why UDP?
 No connection needs to be set up.
 Throughput may be higher because UDP packets
are easier to process, especially at the source.
 The user doesn’t care if the data is transmitted
reliably.
 Example:Real-time video and audio streaming
protocols are designed to handle occasional lost
packets, so only slight degradation in quality
occurs, rather than large delays if lost packets were
retransmitted.
TCP and UDP Functional Comparison

Function TCP UDP

Ordered data transfer This involves a continuous Does not reorder received data.
stream of ordered data.

Multiplexing using ports Receiving hosts decide the Same as TCP.


correct application for which the
data is destined, based on the
port number.
Reliable transfer Acknowledgment of data uses This is not a feature of UDP.
the Sequence and
Acknowledgment fields in the
TCP header.
Flow control This process is used to protect This is not a feature of UDP.
buffer space and routing
devices.

Connections This process is used to initialize UDP is connectionless.


port numbers and other TCP
header fields.
IP addresses versus port numbers
UDP header format
UDP header format
 Source port :This field identifies the sending port.
 Destination port: This field identifies the
destination port and is required.
 Length :16-bit field that specifies the length in
bytes of the entire datagram: header and data.
 Checksum: The 16-bit checksum field is used for
error-checking of the header and data
Checksum calculation
 Checksum is 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 with zero octets at the end (if
necessary) to make a multiple of two octets.
IPv4 PSEUDO-HEADER
Checksum calculation
Encapsulation and decapsulation
Notes
 UDP packets are called user datagrams and have a
fixed-size header of 8 bytes.
 UDP length = IP length − IP header’s length
 Port numbers obtained by Internet Assigned Numbers
Authority (IANA):
Some well-known ports used with
UDP
Port Protocol Description
7 Echo Echoes a received datagram back to
sender
9 Discard Discards diagrams that are received
13 Daytime Returns date and time

17 Quote of the Day Server returns a short arbitrary


message to the client
23 Message Send Protocol used to send a short message
between nodes on a network.
53 Domain Name System translates a host name into an IP
address .
68 Bootstrap Protocol (BOOTP) Client used by a network client to obtain
an IP address from a configuration
server (DHCP).
69 Trivial File Transfer Protocol a very basic form of File Transfer
Protocol (FTP)
Domain Name System(DNS)
 IP addresses are tough for humans to remember.
 IP addresses are impossible to guess.
 The domain name system is usually used to
translate a host name into an IP address .
 Domain names comprise a hierarchy so that names
are unique, yet easy to remember.
DNS and UDP
 DNS primarily uses User Datagram
Protocol (UDP) on port number 53 to serve
requests.
 Single UDP request from the client followed by a
single UDP reply from the server.
 In Domain Name System (DNS), queries must be
fast and only consist of a single request followed
by a single reply packet
Domain Name
 The domain name for a host is the sequence of
labels that lead from the host (leaf node in the
naming tree) to the top of the worldwide naming
tree.
 A domain is a subtree of the worldwide naming
tree.
 Top Level Domains : edu, gov, com, net, org
 Countries each have a top level domain (2 letter
domain name).
Host name structure
 Each host name is made up of a sequence of labels
separated by periods.
 Each label can be up to 63 characters
 The total name can be at most 255 characters.
 Examples:
 whitehouse.gov
 isr.ics.uci.edu
DNS Organization
 Distributed Database
 The organization that owns a domain name is
responsible for running a DNS server that can provide
the mapping between hostnames within the domain to
IP addresses.
 some machine run by UCI is responsible for
everything within the uci.edu domain.
DNS Distributed Database
 There is one primary server for a domain, and
typically a number of secondary servers containing
replicated databases.
uci.edu DNS server

uci.edu
uci.edu rpi.edu
DNSrpi.edu
DB
DNS DB DNS DB
DNS DB

Authoritative Replicas
UDP or TCP
 Both UDP and TCP are used in DNS:
 Generally UDP is used to serve requests.
 If the response data size exceeds 512 bytes, requestor
resubmits request using TCP( i.e. zone transfers) .
DNS Clients
 A DNS client is called a resolver.
 A call to gethostbyname()is handled by a resolver
(typically part of the client).
 Most Unix workstations have the file
/etc/resolv.conf that contains the local
domain and the addresses of DNS servers for that
domain.
/etc/resolv.conf
domain ics.uci.edu
128.195.1.48
The Root DNS Server
 the official DNS root is administered by the Internet
Corporation for Assigned Names and Numbers (ICANN).
 The root server needs to know the address of 1st (and many
2nd) level domain nameservers.

edu com org jp

uci ucsd

ics eng
DNS Servers
 Servers handle requests for their domain directly.
 If a server has no clue about where to find the
address for a hostname, asks the root server. The
root server will tell you what nameserver to
contact.
 A request may get forwarded a few times.
 Servers cache external mappings(since root servers
are bottleneck for trillions of queries placed every
day)
Address resolution mechanism

1-the root server address


is often stored in a file
of root hints, which are
updated periodically by an
administrator from a
reliable source.
2-ask the root server to
find the server
authoritative for the top-
level domain.
3-ask the obtained Top
Level Domain DNS server
for the second-level
domain.
4-Repeating the previous
step
UDP Client and Server Example in
Java
 The server continuously receives datagram packets
over a datagram socket.
 Each datagram packet received by the server indicates
a client request for a quotation.
 When the server receives a datagram, it replies by
sending a datagram packet that contains a one-line
"quote of the moment" back to the client.
 Two classes implement the server application:
QuoteServer and QuoteServerThread. A
single class implements the client application:
QuoteClient.
QuoteServer Class

import java.io.*;
public class QuoteServer {
public static void main(String[] args) throws IOException {
new QuoteServerThread().start();
}
}
The QuoteServerThread Class
public class QuoteServerThread extends Thread {
...
super(name);
socket = new DatagramSocket(4445);
public void run() {
while (moreQuotes) {
try { byte[] buf = new byte[256];
// receive request
DatagramPacket packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);
// figure out response
String dString = null;
dString = getNextQuote();

buf = dString.getBytes();
// send the response to the client at "address" and "port“
InetAddress address = packet.getAddress();
int port = packet.getPort();
packet = new DatagramPacket(buf, buf.length, address, port);
socket.send(packet);
}...}}
The QuoteClient Class

public class QuoteClient {


public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("Usage: java QuoteClient <hostname>");
return; }
// get a datagram socket
DatagramSocket socket = new DatagramSocket();
// send request
byte[] buf = new byte[256];
InetAddress address = InetAddress.getByName(args[0]);
DatagramPacket packet = new DatagramPacket(buf, buf.length,
address, 4445);
socket.send(packet);
// get response
packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);
// display response
String received = new String(packet.getData(), 0, packet.getLength());
System.out.println("Quote of the Moment: " + received);
socket.close();
}
}

You might also like