import java.net.*; import java.io.*; public class EchoClient { public static void main(String[] args) throws Exception { String hostname = "localhost"; DatagramSocket socket; byte[] sendBytes, receiveBytes = new byte[1000]; BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in)); try { socket = new DatagramSocket(); } catch (IOException e) { System.err.println("Could not create socket on port: 10007."); System.exit(1); return; } DatagramPacket myPacket = new DatagramPacket(new byte[1000], 1000); myPacket.setAddress(InetAddress.getByName(hostname)); myPacket.setPort(10007); System.out.println ("Waiting for message....."); while (true) { String theLine = userIn.readLine(); if (theLine.equals(".")) break; sendBytes = theLine.getBytes(); myPacket.setData(sendBytes); socket.send(myPacket); socket.receive(myPacket); String theResponse = new String(myPacket.getData()); System.out.println(theResponse); } } }