public interface Goodbye extends Remote {
String sayGoodbye() throws RemoteException;
}
public class HelloImpl extends UnicastRemoteObject
implements Hello,
Goodbye
{
public HelloImpl() throws RemoteException { }
public String sayHello()
{
return "Hello World!";
}
public
String sayGoodbye() {
return "Goodbye World!";
}
public static void main(String args[]) {
try {
HelloImpl obj = new HelloImpl();
Naming.rebind("HelloServer", obj);
System.out.println("HelloServer bound in registry");
} catch (Exception e) {
System.out.println("HelloServer err: " + e.getMessage());
e.printStackTrace();
}
}
}
Goodbye
obj = (Goodbye) Naming.lookup("rmi://"
+ "lysander.cs.ucsb.edu"
+ "/HelloServer");
System.out.println(obj.sayGoodbye());
} catch (Exception
e) {
System.out.println("GoodbyeClient exception:
" + e.getMessage());
e.printStackTrace();
}
}
}