官术网_书友最值得收藏!

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);
}
}
}
主站蜘蛛池模板: 洞头县| 苏尼特左旗| 酉阳| 利川市| 轮台县| 武威市| 武威市| 临桂县| 叙永县| 宿松县| 界首市| 怀安县| 黎城县| 时尚| 亚东县| 远安县| 奉化市| 余江县| 博兴县| 安新县| 钦州市| 衡水市| 攀枝花市| 宁安市| 辽阳市| 陇川县| 伊金霍洛旗| 牟定县| 芮城县| 平度市| 大厂| 万安县| 普定县| 罗城| 韶关市| 镇雄县| 裕民县| 漾濞| 昌乐县| 吴川市| 辽宁省|