/*
 * Script ?? Exercise 
 *
 * implement RMI example
 *
 */

import java.math.*;
import java.net.*;
import java.rmi.*;
import java.rmi.server.*;

public class ex20c {

  private int l, m;
  RemoteInterface ex;

  public ex20c(int li) {
    l = li; 
  }

  void use() {

    try { ex = (RemoteInterface) Naming.lookup("rmi://localhost/remote"); }
    catch (RemoteException re) {
      System.err.println("RemoteException in ex20c " + re);
      System.exit(-1);
      } 
    catch (NotBoundException nb) {
      System.err.println("NotBoundException " + nb);
      System.exit(-1);
      } 
    catch (MalformedURLException u) {
      System.err.println("MalformedURLException in ex20c " + u);
      System.exit(-1);
      } 
    catch (ClassCastException c) {
      System.err.println("ClassCastException in ex20c " + c);
      System.exit(-1);
      } 

    System.out.println("method found");

    try { m = ex.tuwas(3); 
          System.out.println("answer from tuwas = " + m);
    }
    catch (RemoteException re) {
      System.err.println("RemoteException in ex20c " + re);
      System.exit(-1);
      } 

    System.out.println("method used");
    
  }
  
  /*parameters */
  public static final int t = 1, w = 1000;

  public static String host = ""; 
  public static int port = -1; 
 
  public static void main(String[] args) throws InterruptedException {

    if (args.length >= 1) { 
       try { port = Integer.parseInt(args[0]); } 
       catch (NumberFormatException e) { } 
    } 
    if (args.length >= 2) { 
       host = args[1]; 
    } 

    ex20c s = new ex20c(1);
    s.use();

    System.out.println("termination");
  }

}




