- Distributed Computing in Java 9
- Raja Malleswara Rao Pattamsetti
- 150字
- 2021-07-02 21:02:34
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);
}
}
}
推薦閱讀
- Vue 3移動Web開發(fā)與性能調(diào)優(yōu)實戰(zhàn)
- INSTANT Mock Testing with PowerMock
- 流量的秘密:Google Analytics網(wǎng)站分析與優(yōu)化技巧(第2版)
- Windows系統(tǒng)管理與服務配置
- Learning Informatica PowerCenter 10.x(Second Edition)
- 云計算通俗講義(第3版)
- Hands-On RESTful Web Services with Go
- SAP BusinessObjects Dashboards 4.1 Cookbook
- Android程序設計基礎
- C語言程序設計
- CoffeeScript Application Development Cookbook
- 時空數(shù)據(jù)建模及其應用
- Hands-On Full Stack Development with Spring Boot 2.0 and React
- Java并發(fā)編程之美
- Learning Ionic