Hi.
I wrote this program claculator java rmi.but not implemented.
you can help me?
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface calculator extends Remote {
public long add(long a, long b)
throws RemoteException;
public long sub(long a, long b)
throws RemoteException;
public long mul(long a, long b)
throws RemoteException;
public long div(long a, long b)
throws RemoteException;
}
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
public class calculatorServer extends UnicastRemoteObject implements calculator {
public calculatorServer () throws RemoteException {
super();
}
public long add(long a, long b) {
return a + b;
}
public long sub(long a, long b) {
return a * b;
}
public long mul(long a, long b) {
return a - b;
}
public long div(long a, long b) {
return a / b;
}
public static void main(String args[]) {
try {
Calculatorserver clapton = new Calculatorserver();
Naming.rebind("rmi://localhost:1099/CalculatorService", clapton);
} catch (Exception e) {
System.out.println("Trouble: " + e);
}
}
}
import java.rmi.Naming;
import java.rmi.RemoteException;
public class CalculatorClient {
public static void main(String[] args) {
try {
Calculator clapton = (Calculator)
Naming.lookup(
"rmi://localhost
/CalculatorService");
System.out.println( c.sub(4, 3) );
System.out.println( c.add(4, 5) );
System.out.println( c.mul(3, 6) );
System.out.println( c.div(9, 3) );
}
catch (Exception e) {
System.out.println("Trouble: " + e);
}
}
}