import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { // Explicitly create array of bytes to hold message data byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence; // Create (buffered) input stream using standard input BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in)); // Create client datagram socket ///////////////////////////////////// // ToDo: Look up the java API for the // class DatagramSocket which provides a constructor // with no parameters. Use this constructor to create // a client datagram socket called "clientSocket" ///////////////////////////////////// // Use DNS to resolve domain name to IP address ///////////////////////////////////// // ToDo: Enter the name of your machine as // domain name (using the getByName method of the // InetAddress class, as in Task 1). ///////////////////////////////////// InetAddress IPAddress = InetAddress.getByName(" "); System.out.println("Client ready for input"); // While loop to read and handle multiple input lines while ((sentence = inFromUser.readLine()) != null) { sendData = sentence.getBytes(); // Create message datagram from data and server addressing information DatagramPacket sendPacket = new DatagramPacket( sendData, sendData.length, IPAddress, 9876); // Send to server ///////////////////////////////////// // ToDo: Look up the java API for the // class DatagramSocket which provides // the method send that sends a datagram // packet to the socket // // -> send the datagram packet "sendPacket" // to the client socket "clientSocket" // ///////////////////////////////////// // Create message datagram to hold data from server DatagramPacket receivePacket = new DatagramPacket( receiveData, receiveData.length); // Receive from server ///////////////////////////////////// // ToDo: Look up the java API for the // class DatagramSocket which provides // the method receive that receives a // datagram packet from this socket // // -> receive the datagram packet // "receivePacket" from the client // socket "clientSocket" // ///////////////////////////////////// // Create a string from the data received String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); } // end while, loop to accept more lines from user clientSocket.close(); } // end main } // end class