import java.rmi.*; import java.net.*; public class HelloClient1 { public static void main(String args[]) { // Get the url of the HelloServer String urlServerStr = ""; if( (args.length > 1) || (args.length == 1 && !args[0].startsWith("rmi:")) ) { System.err.println( "Usage: java HelloClient1 [rmi://host.domain:port/helloServer]"); System.exit(1); } else if ( args.length == 0 ) { urlServerStr = "rmi://127.0.0.1:1099/helloServer"; } else { urlServerStr = args[0]; } // Starts Security Manager to download stub_class and execute it ! if( System.getSecurityManager() == null ) { System.setSecurityManager(new LaxSecurityManager()); } try { Hello h = (Hello)Naming.lookup(urlServerStr); String message = h.sayHello(); System.out.println("\n HelloClient1: msg from server -> " + message); } catch (MalformedURLException e) { System.out.println(urlServerStr + " is not a valid RMI URL" + e.getMessage()); e.printStackTrace(); } catch (RemoteException e) { System.out.println("Remote object threw exception " + e.getMessage()); e.printStackTrace(); } catch (NotBoundException e) { System.out.println("Could not find the requested remote object: " + e.getMessage()); e.printStackTrace(); } catch (Exception e) { System.out.println("Exception in main: " + e); e.printStackTrace(); } } }