JAVA RMI
import java.rmi.*;
public interface RemoteInterface extends Remote {
public int tuwas(int l) throws RemoteException;
}
import java.rmi.*;
import java.rmi.server.*;
public class RemoteExam
extends UnicastRemoteObject
implements RemoteInterface {
private int id = -1;
public RemoteExam() throws RemoteException {
super();
id = 0;
}
public int tuwas(int l) throws RemoteException {
return id+l;
}
}
private int l;
public RemoteExam ex;
public void register() {
try { ex = new RemoteExam(); }
catch (RemoteException re) {
System.err.println("Can not create RemoteExam.");
System.exit(-1);
}
/* register */
try { Naming.rebind("remote", ex); }
catch (RemoteException re) {
System.err.println("RemoteException in bind.");
System.exit(-1);
}
catch (MalformedURLException u) {
System.err.println("MalformedURLException in bind.");
System.exit(-1);
}
System.out.println("method registered");
}
private int l, m;
RemoteInterface ex;
void use() {
try { ex = (RemoteInterface) Naming.lookup("rmi://localhost/remote"); }
catch (RemoteException re) {
System.err.println("RemoteException in ex20c " + re);
System.exit(-1);
}
catch (NotBoundException nb) {
System.err.println("NotBoundException " + nb);
System.exit(-1);
}
catch (MalformedURLException u) {
System.err.println("MalformedURLException in ex20c " + u);
System.exit(-1);
}
catch (ClassCastException c) {
System.err.println("ClassCastException in ex20c " + c);
System.exit(-1);
}
System.out.println("method found");
try { m = ex.tuwas(3);
System.out.println("answer from tuwas = " + m);
}
catch (RemoteException re) {
System.err.println("RemoteException in ex20c " + re);
System.exit(-1);
}
System.out.println("method used");
}
Remote Interface, Remote Example, ex20s.java Server, ex20c.java Client.
listrmireg.java List RMI registry.
SmallPrime Interface, SmallPrime Implementation, ex21s.java Server, ex21c.java Client.
ex21.out Beispiel trumpf-10, ex21-c.out Beispiel comyc.
[Previous]
[Next]
[Contents]