import java.io.*;
import java.net.*;
import javagently.*;

class Ports {
  /* The Ports porgram            J M Bishop 1997
   * -----------------		    updated August 2000
   *
   * For checking the response from various ports
   * on a remote computer.
   * Illusrates sockets
   */

  public static void main(String[] args) {
    String computer;
    int port;

    if (args.length > 0) computer = args[0];
    else computer = "syd.cs.up.ac.za";
    if (args.length > 1) port = Integer.parseInt(args[1]);
    else port = 13; // the clock port

    new Ports (computer, port);
  }

  Ports (String computer, int port) {

    System.out.println("Accessing port "+port+" on "+ computer+"\n");
    try {

      // Create a socket to the given port.
      // Set up an input stream to read what the socket on that
      // side provides.

      Socket t = new Socket(computer, port);
      Stream in = new Stream(t.getInputStream());

      // Read from the server until readLine
      // returns no more data
      while (true) {
        String s = in.readLine();
        if (s == null) break;
        else System.out.println(s);
      }
    }
    catch(IOException e) { System.out.println("Error" + e); }
  }
}
