UDP Protocol Example

UDP Protocol Example

UDP Protocol Example

Summary: All the earlier programs are based on TCP/IP protocol. Here "UDP Protocol Example" discusses the basics of UDP protocol. Later postings gets you the programs.

User Datagram Protocol (UDP)

It is advised to go through the network and socket basics before proceeding to the UDP protocol.

UDP stands for User Datagram Protocol. The UDP protocol does not use I/O streams in data transmission (TCP/IP uses I/O streams as you have practiced in the earlier programs). The data is divided into a number of packets and each packet is known as a datagram. To handle datagrams, the java.net package include classes like DatagramPacket and DatagramSocket. DatagramSocket is capable of both sending and receiving the datagram packets with methods send() and receive(). In programming a datagram packet is represented as an array of bytes. UDP protocol does not have the concept of server socket. One more difference is the destination system address and port number lie with Socket in case of TCP/IP protocol where as with UDP, they lie with the datagram packet in the form of a header.

UDP protocol is known as connectionless protocol and TCP/IP protocol is known as connection-oriented protocol. The UDP protocol is unreliable in data transmission and TCP/IP is known as reliable. An unreliable protocol does not give guarantee of the delivery of data packets. For this reason, use UDP for transmitting unimportant data like music and animations etc. Note that the port numbers are different for both protocols. Each will have port numbers upto the extent of 65,535.

UDP Clients – UDP Protocol Examples

On UDP Protocol Examples, two applications are given with different functionality.

  1. 1st Application: Server sending data to Client
  2. 2nd Application: Client sending and receiving the message; Echo Server

Leave a Reply

Your email address will not be published. Required fields are marked *