/* * SocketWriter.java * * Created on November 29, 2002, 3:19 AM */ /** * * @author Nathan Balon * IS 375 * SocketWriter * program #8 * @version */ import java.net.Socket; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.PrintWriter; public class SocketWriter { /** * @param args the command line arguments */ public static void main (String args[]) { if(args.length < 2){ System.out.println("USAGE: java SocketWriter hostname port"); System.exit(1); } //if String host = new String(args[0]); String portStr = new String(args[1]); int port = Integer.parseInt(portStr); try{ Socket socket = new Socket (host, port); BufferedReader in = new BufferedReader (new InputStreamReader(socket.getInputStream())); PrintWriter out = new PrintWriter( incoming.getOutputStream(), true); boolean done = false; System.out.println("Type the sentences you want to send. " + "Type 'exit' to quit"); while(!done){ String line = in.readLine(); if(!line.startsWith("exit")){ out.println(line); }//if else{ // stop reader out.println("~READER_STOP~"); done = true; }//else }//while // close the socket socket.close(); }//try catch(Exception e){ e.printStackTrace(); System.exit(1); } // catch }// main }