UDP Flashcards
What is UDP?
UDP (User Datagram Protocol) is a connectionless transport-layer protocol for lightweight and fast communication over IP networks, offering no reliability or order guarantees.
What are the key features of UDP?
Connectionless Service: No connection setup or teardown; direct communication.
Best-Effort Delivery: No built-in error recovery; packets may be lost, duplicated, or arrive out of order.
Supports multicast messaging.
What are common applications of UDP?
Instant Messaging: e.g., ICQ.
Multicast Messaging: Efficient for multiple receivers.
Low-Latency Communication: e.g., Voice-over-IP (VoIP), streaming, and gaming.
What is the structure of a UDP datagram?
1.Header (8 bytes):
*Source Port (2 bytes).
*Destination Port (2 bytes).
*Length (2 bytes): Total datagram length.
*Checksum (2 bytes): For error-checking.
2.Data: Variable-size payload with the application message.
What is the purpose of ports in UDP?
Ports: Logical endpoints for communication.
Allow multiple applications to use the same network connection.
Examples of well-known ports:
*Port 25: SMTP (Email).
*Port 80: HTTP (Web).
*Port 90: SHTTP (Secure Web).
How is UDP encapsulated?
UDP datagrams are encapsulated in IP datagrams, with the following hierarchy:
Frame Header (network-specific).
IP Header (internet addressing).
UDP Header (port and checksum data).
User Data (application message).
What are the advantages and limitations of UDP?
Advantages:
*Minimal overhead.
*Fast and suitable for real-time applications.
Limitations:
*No reliability, retransmission, or acknowledgment.
*Applications must manage reliability and data ordering.
Provide an example of sending and receiving data using UDP in Java.
Sending Data: DatagramSocket socket = new
DatagramSocket(16789);
String msg = “hello”;
String IP = “229.201.35.83”;
InetAddress address = InetAddress.getByName(IP);
DatagramPacket outputPacket = new
DatagramPacket(msg.getBytes(), msg.length(), address,
12465);
socket.send(outputPacket);
Receiving Data: DatagramSocket socket = new
DatagramSocket(16789);
byte[] data = new byte[256];
DatagramPacket inputPacket = new DatagramPacket(data, 256);
socket.receive(inputPacket);