import java.rmi.*; // USAGE: java AddClient firstNum secondNum public class AddClient { public static void main(String args[]) { // The client will try to download code, in particular, it will // be downloading stub class from the server. // Any time code is downloaded by RMI, a security manager must be present. if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } try { String addServerURL = "rmi://" + args[0] + ":" + args[1] + "/MyAddServer"; System.out.println("I will try to invoke the remote method from " + addServerURL); AddServerIntf remoteObj = (AddServerIntf) Naming.lookup(addServerURL); System.out.println("The first number is: " + args[2]); double d1 = Double.valueOf(args[2]).doubleValue(); System.out.println("The second number is: " + args[3]); double d2 = Double.valueOf(args[3]).doubleValue(); // Now we invoke from a local machine the remote method "add" System.out.println("The sum is: " + remoteObj.add(d1, d2)); } catch(Exception e) { System.out.println("Exception: " + e); } } }