import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Server {
public static void main(String[] args) {
try {
ImplExample obj = new ImplExample();
Registry registry = LocateRegistry.createRegistry(1099);
registry.rebind("Hello", obj);
System.out.println("Server is running...");
}
catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Client {
public static void main(String[] args) {
try {
Registry registry = LocateRegistry.getRegistry("localhost", 1099);
Hello stub = (Hello) registry.lookup("Hello");
String response = stub.sayHello();
System.out.println("\nResponse from Server: " + response + "\n");
}
catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
}
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class ImplExample extends UnicastRemoteObject implements Hello {
protected ImplExample() throws RemoteException {
super();
}
public String sayHello() throws RemoteException {
return "Hello, World!";
}
}
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}