public static void main(String[] args) {
    if (System.getSecurityManager() == null) {
      System.setSecurityManager(new RMISecurityManager());
    }
    
    int port = 1099;
    InetAddress localhost = null;
    try {
      localhost = InetAddress.getLocalHost();
      System.err.println("Host name : "+localhost.getHostName());
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    String name;
    if (localhost != null) {
      name = localhost.getHostName();
    } else {
      name = "localhost";
    }
    
    // get optional port
    try {
      String portOption = Utils.getOption("p", args);
      if (!portOption.equals("")) 
        port = Integer.parseInt(portOption);
    } catch (Exception ex) {
      System.err.println("Usage : -p <port>");
    }

    if (port != 1099) {
      name = name + ":" + port;
    }
    name = "//"+name+"/RemoteEngine";
    
    try {
      Compute engine = new RemoteEngine(name);
      
      try {      
        Naming.rebind(name, engine);
        System.out.println("RemoteEngine bound in RMI registry");
      } catch (RemoteException ex) {
        // try to bootstrap a new registry
        System.err.println("Attempting to start RMI registry on port " + port + "...");
        java.rmi.registry.LocateRegistry.createRegistry(port);
        Naming.bind(name, engine);
        System.out.println("RemoteEngine bound in RMI registry");
      }
      
    } catch (Exception e) {
      System.err.println("RemoteEngine exception: " + 
			 e.getMessage());
      e.printStackTrace();
    }
  }