public interface RemoteInterface {
public String doSomething();
}
public class RemoteImplementation implements RemoteInterface {
public String doSomething() {
return "Hello, Remote World!";
}
}
public class Server {
public static void main(String[] args) {
RemoteInterface implementation = new RemoteImplementation();
Registry registry = LocateRegistry.createRegistry(1099);
registry.rebind("RemoteObject", implementation);
System.out.println("Server started!");
}
}
public class Client {
public static void main(String[] args) {
try {
Registry registry = LocateRegistry.getRegistry("localhost", 1099);
RemoteInterface remoteObject = (RemoteInterface) registry.lookup("RemoteObject");
String result = remoteObject.doSomething();
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
}