import java.io.*; import java.net.*; //adapted from Sun's KnockKnockClient example from the Java Tutorial public class TransClient { public static void main(String[] args) throws IOException { String host = "localhost"; if (args.length>0) { host=args[0]; } Socket transSocket = null; PrintWriter out = null; BufferedReader in = null; try { transSocket = new Socket(host, 4444); out = new PrintWriter(transSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(transSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host: " + host); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: " + host); System.exit(1); } BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); String fromServer; String fromUser; while ((fromServer = in.readLine()) != null) { if (fromServer.length()>0) { System.out.println("GoogleTranslate: " + fromServer); } if (fromServer.equals("Bye.")) break; System.out.print("\"Bye\" to quit > "); fromUser = stdIn.readLine(); if (fromUser != null) { out.println(fromUser); } } out.close(); in.close(); stdIn.close(); transSocket.close(); } }