import java.io.*; import java.net.*; import java.util.*; public class Client { // IO streams for sending/receiving primitive data types private DataOutputStream toServer; private DataInputStream fromServer; public static void main( String[] args ) { new Client(); } public Client() { // Object to read keyboard input from the user Scanner keyboard = new Scanner( System.in ); try { // Create a socket to connect to the server Socket socket = new Socket( "localhost", 8123 ); // Socket socket = new Socket( "monica.cs.rpi.edu", 8123 ); // Socket socket = new Socket( "128.213.7.2", 8123 ); // Create an input stream to receive data from the server fromServer = new DataInputStream( socket.getInputStream() ); // Create an output stream to send data to the server toServer = new DataOutputStream( socket.getOutputStream() ); while ( true ) { // Get the radius from the user System.out.print( "Enter radius: " ); double radius = keyboard.nextDouble(); // Send the radius to the server toServer.writeDouble( radius ); toServer.flush(); System.out.println( "Sent radius " + radius + " to server" ); // Get area from the server double area = fromServer.readDouble(); // Display to the text area System.out.println( "Area received from server is " + area ); } } catch ( IOException ex ) { System.err.println( ex ); } } }