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

public class FingerProxy extends MTServerBase {
    static String parentHost;

    void socketClose() {
    try {
      socket.close();
      }
    catch (IOException e) {}
    }

    public void run() {
	Finger fing = new Finger();
	BufferedReader is;
	OutputStreamWriter os;
	String s;
	String cmd;
	try {
	    is = new BufferedReader(
	      new InputStreamReader(socket.getInputStream()));
	    os = new OutputStreamWriter(socket.getOutputStream(),
	      "iso8859_1");
            }
	catch (Exception ioe) {
	   System.out.println("Can't create streams\n" + ioe);
	   socketClose();
	   return;
           }
   // read command line
   try {
     cmd=is.readLine();
     }
   catch (IOException e) {
     socketClose();
     return;
    }
   

   try {
      s=fing.finger(parentHost,cmd);
      os.write(s,0,s.length());
      os.flush();
      }
    catch (IOException we) {
      System.out.println("Write exception: " + we);
      }
  socketClose();
  }

  public static void main(String [] args) {
    parentHost=args[0];
    startServer(79,FingerProxy.class);
    }
}
