Unit-10 UDP
Unit-10 UDP
➢ In network programming with Java, UDP (User Datagram Protocol) is one of the transport protocols used for sending and receiving datagrams over
a network.
➢ UDP is a connectionless protocol, which means that it doesn't establish a persistent connection between the sender and receiver. Instead, it sends
individual packets called datagrams from one host to another.
➢ UDP (User Datagram Protocol) is an important transport protocol in computer networking due to the following reasons:
1. Simplicity and Efficiency: UDP is lightweight and doesn't have the overhead of establishing and maintaining connections, making it faster and
more efficient for certain applications.
2. Low Latency: UDP offers low latency by avoiding acknowledgments and retransmissions, making it suitable for real-time applications where
immediate data delivery is crucial.
3. Broadcast and Multicast: UDP supports broadcasting and multicasting, allowing a single packet to be sent to multiple recipients simultaneously,
which is useful for streaming media and online gaming.
4. Stateless Communication: UDP is stateless, enabling scalability for server applications that handle a large number of clients.
5. VoIP and Streaming: UDP is commonly used in Voice over IP (VoIP) and multimedia streaming applications, where real-time transmission takes
priority over reliability.
6. DNS: UDP is utilized by DNS for name resolution queries, which are typically small and time-sensitive.
7. Internet of Things (IoT): UDP is frequently used in IoT devices and applications, where quick and efficient transmission of small data packets is
essential. ALPINE SKI HOUSE 1
Krishna Pd. Acharya
STRUCTURE OF A UDP DATAGRAM
Client UDP:
3. Convert your data into bytes and store it in the DatagramPacket object.
4. Specify the destination address and port number of the server by creating an instance of InetAddress and specifying the server's IP
address and port number.
5. Use the send() method of the DatagramSocket object to send the DatagramPacket to the server.
1. Create a DatagramSocket object and bind it to a specific port number on the server machine.
3. Create a DatagramPacket object to receive the incoming UDP packet and specify the size of the buffer.
4. Use the receive() method of the DatagramSocket object to receive the DatagramPacket.
5. Extract the data from the DatagramPacket object and process it as needed.
6. Optionally, send a response back to the client by creating a new DatagramPacket and using the send() method of the DatagramSocket.