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

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);
}
}
}
主站蜘蛛池模板: 苍南县| 安化县| 长泰县| 杭锦后旗| 巩义市| 肥东县| 和田市| 黔东| 卓尼县| 永定县| 阜平县| 武定县| 光山县| 贞丰县| 宁阳县| 娱乐| 瑞丽市| 扎赉特旗| 迁安市| 色达县| 沂源县| 盐津县| 甘孜| 栖霞市| 宜宾市| 临西县| 南涧| 海伦市| 吐鲁番市| 铜鼓县| 蓬溪县| 合作市| 保定市| 孟连| 河东区| 望奎县| 德惠市| 枣阳市| 元谋县| 台江县| 邛崃市|