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

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);
}
}
}
主站蜘蛛池模板: 东方市| 宁波市| 三原县| 通海县| 信阳市| 涿鹿县| 福贡县| 崇明县| 曲水县| 清河县| 平原县| 镇巴县| 长春市| 孟津县| 潞西市| 开鲁县| 东平县| 仁化县| 嘉峪关市| 伊川县| 赤壁市| 五寨县| 晴隆县| 乐亭县| 行唐县| 彰武县| 商都县| 吉隆县| 西充县| 石楼县| 庆城县| 普宁市| 桂东县| 广德县| 买车| 申扎县| 井冈山市| 淮北市| 拜城县| 潢川县| 凉山|