-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
33 lines (27 loc) · 1.32 KB
/
Client.java
File metadata and controls
33 lines (27 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Client {
public static void main(String[] args) {
try {
// Step 1: Connect to RMI registry
Registry registry = LocateRegistry.getRegistry("localhost", 1099);
// Step 2: Lookup the remote object
Arithmetic stub = (Arithmetic) registry.lookup("ArithmeticService");
// Step 3: Perform arithmetic operations
double a = 10, b = 5;
System.out.println("✅ Arithmetic Operations from Remote Server:");
System.out.println("Addition: " + stub.add(a, b));
System.out.println("Subtraction: " + stub.subtract(a, b));
System.out.println("Multiplication: " + stub.multiply(a, b));
System.out.println("Division: " + stub.divide(a, b));
} catch (RemoteException e) {
System.err.println("❌ RemoteException: " + e.getMessage());
} catch (NotBoundException e) {
System.err.println("❌ Service not found in registry: " + e.getMessage());
} catch (Exception e) {
System.err.println("❌ Unexpected exception: " + e.getMessage());
}
}
}