Client Server Program in Java Using UDP

In Internet the traffic is control by strict protocol.There are two types of Internet Protocol(IP)

Types of Internet Protocol(IP)

1. TCP (Transmission Control Protocol ) and
2.UDP (User or Universal  Datagram Protocol)

TCP is connection oriented – reliable protocol which transfer the data in continues streams.once a connection is established, data can be sent bidirectional. It is a two way communication.

UDP means a Datagram  is a  connection less ,independent , self contained protocol. Bulk Data  are send and receive  as packets from using UDP.

The package contain three classes to help write a java program that use datagrams to send and receive packets over the network.

1 DatagramSocket :

To create the UDP Socket and to send and receive the data packet

2 DatagramPacket :

To create packet for data

3 MulticastSocket :

Datagrampacket through DatagramSocket can be broadcast to multiple recipients.

Differ type of Definition for  Chat Program using UDP (Datagram)

How to make Client send message  to Server  and server receive it in packet form

write a java program  Client  send message server receive this message   using UDp transport layer

Example Program of Datagram layer client write  some message and server read it.

Source Code for  Server

Source Code for  Client


Output of client-server  Chat Program in JAVA using Datagram

First two different cmd(command prompt) window open on   screen

now we seen two different cmd window screen  on monitor now do this step

step-1   e:>javac on cmd screen-1

step-2  e:>javac on cmd screen-1

step-3  e:>java UDPServer on cmd screen-1

step-4  e:>java UDPClient on cmd screen-2

For Better Understanding see on the below Screenshot


(Visited 4,143 times, 13 visits today)

Leave a Reply

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

Reload Image