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

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);
}
}
}
主站蜘蛛池模板: 五原县| 永年县| 怀安县| 徐闻县| 铜鼓县| 肥城市| 内丘县| 司法| 防城港市| 克拉玛依市| 卫辉市| 洛南县| 深圳市| 绥宁县| 延边| 冕宁县| 九龙县| 延长县| 甘南县| 辽宁省| 吴堡县| 温州市| 平江县| 宁海县| 伽师县| 德保县| 时尚| 崇仁县| 仁化县| 武胜县| 涞水县| 肃宁县| 峡江县| 修武县| 澳门| 雷山县| 上杭县| 阳城县| 论坛| 闵行区| 东至县|