Creating a client program

The server program used to perform the calculation is relatively simple compared to the client program, which needs to handle the RMI along with computation calls.

In our example, the client program communicates with the remote program through the remote application naming invocation and by calling the remote interface methods:

package local;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import remote.Calculate;
public class CalculateClient {
public static void main(String[] args) {
try {
Calculate remoteCalculate = (Calculate)
Naming.lookup("rmi://localhost:5000/calculate");
System.out.println("Remote Addition Result : " +
remoteCalculate.add(4, 5));
System.out.println("Remote Subtraction Result : " +
remoteCalculate.sub(4, 3));
System.out.println("Remote Multiplication Result : " +
remoteCalculate.mul(3, 6));
System.out.println("Remote Division Result : " +
remoteCalculate.div(9, 3));
}
catch (MalformedURLException me) {
System.out.println("MalformedURLException" + me);
}
catch (RemoteException re) {
System.out.println("RemoteException" + re);
}
catch (NotBoundException ne) {
System.out.println("NotBoundException" + ne);
}
catch (java.lang.ArithmeticException ae) {
System.out.println("ArithmeticException" + ae);
}
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset