INF 123 Lecture 4
INF 123 Lecture 4
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
Ordered data transfer This involves a continuous Does not reorder received data.
stream of ordered data.
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.
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
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