/*
 * Script ?? Exercise 
 *
 * implement RMI example
 *
 */

import java.math.*;
import java.net.*;
import java.rmi.*;
import java.rmi.server.*;


public class ex20s {

  private int l;
  public RemoteExam ex;

  public void register() {

    try { ex = new RemoteExam(); }
    catch (RemoteException re) {
      System.err.println("Can not create RemoteExam.");
      System.exit(-1);
      } 

    /* list */
    try { String s[] = Naming.list("rmi://localhost/"); 
          for (int i=0; i < s.length; i++) {
              System.out.println("s = " + s[i]);
          }
          System.out.println("all items listed");
    }
    catch (RemoteException re) {
      System.err.println("RemoteException in list.");
      System.exit(-1);
      } 
    catch (MalformedURLException u) {
      System.err.println("MalformedURLException in list.");
      System.exit(-1);
      } 

    /* register */
    try { Naming.rebind("remote", ex); }
    catch (RemoteException re) {
      System.err.println("RemoteException in bind.");
      System.exit(-1);
      } 
    catch (MalformedURLException u) {
      System.err.println("MalformedURLException in bind.");
      System.exit(-1);
      } 

    System.out.println("method registered");
    
  }
  
  /*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]; 
    } 

    ex20s s = new ex20s();
    s.register();

    System.out.println("termination");
  }

}




