//UDPLocalClient1.java import java.io.*; import java.net.*; public class UDPLocalClient1 { public static void main(String args[]) { DatagramSocket udpSock = null; int port = 7777; String strRead; BufferedReader inStream = new BufferedReader(new InputStreamReader(System.in)); try { udpSock = new DatagramSocket(); InetAddress host = InetAddress.getByName("localhost"); while(true) { //take input and send the packet echo("Enter Your messages : "); strRead = (String)inStream.readLine(); byte[] dsByte = strRead.getBytes(); DatagramPacket dp = new DatagramPacket(dsByte,dsByte.length,host,port); udpSock.send(dp); //buffer to receive incoming data byte[] buffer = new byte[65536]; DatagramPacket reply = new DatagramPacket(buffer, buffer.length); udpSock.receive(reply); byte[] data = reply.getData(); strRead = new String(data, 0, reply.getLength()); //echo the details of from the server echo(reply.getAddress().getHostAddress() + " : " + reply.getPort() + " - " + strRead); } } catch(IOException e) { System.err.println("IOException " + e); } } //simple function to echo data to terminal public static void echo(String msg) { System.out.println(msg); } }