| |
.:For Network Programming
( SCN 4223 ) Purpose Only:.
|
AC990856
Page |
| |
| --»Assignment
6 --- RMI SQRT |
| --SQRT Interface |
import java.rmi.*;
interface MethodImpl extends Remote
{
double getSqrt(double dbl) throws RemoteException;
}
|
| --SQRT Server |
| import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
public class RMIServer extends UnicastRemoteObject implements MethodImpl {
public RMIServer() throws RemoteException {
System.out.println("The server is instantiated");
}
public double getSqrt(double dbl) {
return Math.sqrt(dbl);
}
public static void main(String[] args) {
try {
RMIServer server = new RMIServer();
Naming.rebind("sqrt", server);
}
catch (Exception e) {
System.out.println("Error --" + e.toString());
}
}
}
|
| --SQRT Client |
| import java.rmi.*;
import java.rmi.registry.*;
public class RMIClient {
public static void main(String[] args) {
try {
MethodImpl mthdImpl = (MethodImpl)Naming.lookup("rmi://127.0.0.1/sqrt");
double dbl = mthdImpl.getSqrt(100);
System.out.println("Square root : " + dbl);
}
catch (Exception e) {
System.out.println("Error: " + e.toString());
}
}
}
|
| |
| |