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

class EchoClient {

  public static void main(String[] args) {
    try {
      String host; 
      if (args.length > 0 && args[0] != null) {
	host = args[0]; 
      } else {
	host = "localhost"; 
      }
      Socket t = new Socket(host, 8008); 
      BufferedReader in 
	= new BufferedReader(new InputStreamReader(t.getInputStream())); 
      PrintWriter out 
	= new PrintWriter(new OutputStreamWriter(t.getOutputStream())); 

      for (int i = 1; i <= 10; i++) {
	System.out.println("Sending: line " + i); 
	out.println("line " + i); 
	out.flush();
      }
      out.println("BYE"); 
      out.flush();

      for (;;) {
        String str = in.readLine(); 
        if (str == null) {
          break; 
        } else {
          System.out.println(str); 
        }
      }
    } catch (Exception e) { 
      System.out.println("Error: " + e); 
    }
  }

}
