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

public class Socket2 {
  //run finger on a given host to find information about a given user
  private static final int FINGERPORT = 79;

  public static void main(String[] args) {

    if ( args.length < 1 ) {
      System.err.println("Socket2 <hostname> <username>");
      System.exit(1);
    }
    String host = args[0];
    String user = args[1];

    try {
      Socket socket = new Socket( host, FINGERPORT );
      PrintWriter out = new PrintWriter( socket.getOutputStream() );
      out.println( host + " " + user );
      out.flush();

      BufferedReader in = new BufferedReader(
								new InputStreamReader( socket.getInputStream() ) );
      String result;
      while ( ( result = in.readLine() ) != null ) {
        System.out.println( result );
      }
      out.close();
      in.close();
      socket.close();
    }
    catch( IOException exception ) {
      System.err.println( exception );
    }

  }// end main
}  // end Socket2
