Browse Source

rmi initial version

master
Sebastian Rieger 7 years ago
parent
commit
1581cafff5
  1. 25
      VerteilteSysteme-Examples/src/verteiltesysteme/rmi/RMIEchoClient.java
  2. 9
      VerteilteSysteme-Examples/src/verteiltesysteme/rmi/RMIEchoInterface.java
  3. 36
      VerteilteSysteme-Examples/src/verteiltesysteme/rmi/RMIEchoServer.java

25
VerteilteSysteme-Examples/src/verteiltesysteme/rmi/RMIEchoClient.java

@ -0,0 +1,25 @@
package verteiltesysteme.rmi;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class RMIEchoClient {
private RMIEchoClient() {}
public static void main(String[] args) {
String host = (args.length < 1) ? null : args[0];
try {
Registry registry = LocateRegistry.getRegistry(host);
RMIEchoInterface stub = (RMIEchoInterface) registry.lookup("RMIEchoInterface");
String response = stub.toLowerCase("hAlLo");
System.out.println("response: " + response);
response = stub.toUpperCase("hAlLo");
System.out.println("response: " + response);
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
}

9
VerteilteSysteme-Examples/src/verteiltesysteme/rmi/RMIEchoInterface.java

@ -0,0 +1,9 @@
package verteiltesysteme.rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RMIEchoInterface extends Remote {
public String toLowerCase(String input) throws RemoteException;
public String toUpperCase(String input) throws RemoteException;
}

36
VerteilteSysteme-Examples/src/verteiltesysteme/rmi/RMIEchoServer.java

@ -0,0 +1,36 @@
package verteiltesysteme.rmi;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class RMIEchoServer implements RMIEchoInterface {
public RMIEchoServer() {}
public static void main(String args[]) {
try {
RMIEchoServer obj = new RMIEchoServer();
RMIEchoInterface stub = (RMIEchoInterface) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind("RMIEchoInterface", stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
@Override
public String toLowerCase(String input) throws RemoteException {
return input.toLowerCase();
}
@Override
public String toUpperCase(String input) throws RemoteException {
return input.toUpperCase();
}
}
Loading…
Cancel
Save