import java.io.*; import java.net.*; public class KnockKnockClient { public static void main(String[] args) throws IOException { Socket kkSocket = null; PrintWriter out = null; BufferedReader in = null; try { kkSocket = new Socket("localhost", 4444); out = new PrintWriter(kkSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host: localhost."); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: localhost."); System.exit(1); } BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); String fromServer; //String fromUser; //while ((fromServer = in.readLine()) != null) { // ------------------------------------------ try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("/sbin/route"); // Convert our input stream to a // DataInputStream DataInputStream fromUser = new DataInputStream(fstream); // Continue to read lines while // there are still some left to read while (fromUser.available() !=0) { // Print file line to screen out.println (fromUser.readLine()); } fromUser.close(); } catch (Exception e) { System.err.println("File input error"); } // ------------------------------------------ //fromUser = "Some string ABC"; // send it to server /* if (fromUser != null) { out.println(fromUser); //out.println("Bye."); }*/ //} System.out.println("Closing connection."); out.close(); in.close(); stdIn.close(); kkSocket.close(); } }