1. import java.rmi.*;
2. public class NumFunIm extends java.rmi.server.UnicastRemoteObject
3. implements NumFun {
4. public NumFunIm() throws RemoteException { super(); }
5. public boolean isPrime(long n) throws RemoteException {
6. if (n < 2 || n > 2 && n%2 == 0) return false;
7. long m = (long)Math.sqrt(n) + 1;
8. for (long i = 3; i <= m; i += 2)
9. if (n%i == 0) return false;
10. return true;
11. }
12. public long gcd(long u, long v) throws RemoteException {
13. for ( ; ; ) {
14. long r = u % v;
15. if (r == 0) return v;
16. u = v;
17. v = r;
18. }
19. }
20. public long lcm(long u, long v) throws RemoteException {
21. return u*v/gcd(u,v);
22. }
23. }
Running the System
Open three DOS windows:
1. Compile Server (Window 1)
...\rmiNFS\server>javac NFServer.java
2. Compile the implementation (Window 2)
...\rmiNFS\server>rmic NumFunIm
3. Compile the Client (Window 3)
...\rmiNFC\client>javac NFClient.java
4. Start the RMI registry (Window 2)
...\rmiNFC\client>rmiregistry
5. Run the server (Window 1)
...\rmiNFS\server>java NFServer
6. Run the client (Window 2)
...\rmiNFC\client>java NFClient
Default Output
Using the clients default arguments, 17, 12 and 18 produces the
following output:
17 is a prime
The GCD of 12 and 18 is 6
The LCM of 12 and 18 is 36
Next Page