//------------------------------------------------------------------------- // File: Client.java // // Created by: Tamer Elsharnouby (sharno@cs.umd.edu) // // Course: Project 1, CMSC417-0101 Fall 1999 // // Description: Creates a client that starts a ClientThread (which talks to // server), gets queries from user via standard input and passes // them to ClientThread. Does NOT get intimation of acks. // //------------------------------------------------------------------------- import java.net.*; import java.lang.*; import java.util.*; import java.io.*; import ClientThread; // Class Client // // Starts a ClientThread (which talks to server), gets queries from user // via standard input and passes them to ClientThread. // // Attributes: // cl : The ClientThread. // stdIn : Standard input buffer. // // Methods: // main : The main method for Client class. //----------------------------------------------------------------------- class Client { static ClientThread cl = null; static BufferedReader stdIn = null; //-------------------------------------------------------------------- // Method: main // // Run body of client. Starts a ClientThread, gets queries from user // via standard input and passes them to ClientThread. // // Parameters: // args : Arguments passed to ClientThread indicating server host/port // // Variables : none // // Returns : none public static void main (String[] args){ // create ClientThread and run it cl = new ClientThread(args); cl.start(); // create buffer to standard input. try { stdIn = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { System.err.println ("Failure in constructing System reader"); e.printStackTrace(); } try { while (true){ // Get query to be sent String str = stdIn.readLine(); // Pass query to ClientThread cl.sendPacket(str); // Exit the loop in case query is "Bye" if (str.equals("Bye")) break; } // End ClientThread cl.stop(); } catch (Exception e){ System.err.println("Out to code"); // "Out to code ???" e.printStackTrace(); } }//---------------------- method main --------------------------------- } //------------------ Class Client -------------------------------------