- 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);
}
}
}
推薦閱讀
- C語言程序設計實踐教程(第2版)
- Rust實戰(zhàn)
- C# Programming Cookbook
- Java:Data Science Made Easy
- 零基礎學Python網(wǎng)絡爬蟲案例實戰(zhàn)全流程詳解(高級進階篇)
- Learning ArcGIS for Desktop
- 數(shù)據(jù)結構與算法分析(C++語言版)
- 領域驅(qū)動設計:軟件核心復雜性應對之道(修訂版)
- 劍指大數(shù)據(jù):企業(yè)級數(shù)據(jù)倉庫項目實戰(zhàn)(在線教育版)
- Mastering Python Design Patterns
- 小型編譯器設計實踐
- 區(qū)塊鏈項目開發(fā)指南
- 從程序員角度學習數(shù)據(jù)庫技術(藍橋杯軟件大賽培訓教材-Java方向)
- 零基礎輕松學C++:青少年趣味編程(全彩版)
- 實驗編程:PsychoPy從入門到精通