import java.io.*;
import java.net.*;

/**
 * Example of how to make a very simple java client.
 * Run this as: java ClientListen &lt;host&gt; &lt;port&gt; &lt;filename&gt;
 * 
 * The client dumps the file down the socket, and
 * then prints the server response.
 *
 * @author Rimon Barr
 * @version 1.0, 02/11/99
 */
public class ClientListen {
  public static void main(String args[]) {
    try {
      int port=Integer.valueOf(args[1]).intValue();
      Socket s=new Socket(args[0], port);
      BufferedReader fin=new BufferedReader(new FileReader(args[2]));
      String line=fin.readLine();
      PrintWriter out=new PrintWriter(s.getOutputStream());
      BufferedReader sin=new BufferedReader(new InputStreamReader(s.getInputStream()));
      while(line!=null) {
        out.println(line);
        line=fin.readLine();
      }
      out.flush();
      line=sin.readLine();
      while(line!=null) {
        System.out.println(line);
        line=sin.readLine();
      }
    }
    catch (NumberFormatException e) {
      System.err.println("Invalid port number: "+args[0]);
    }
    catch (ArrayIndexOutOfBoundsException e) {
      System.err.println("Must pass in a hostname, port, filename");
    }
    catch (IOException e) {
      System.err.println(e);
    }
  }
}
