I'm trying to use the RMI Client-Server communication. I wrote the following class/interface:
- Interface RemoteInterface extends Remote
- Class HelloStub extends UnicastRemoteObject implements RemoteInterface
- Class Server, which I binded the remote obj
Class Client as follow:
import java.rmi.*; public class Client { public static void main(String[] args) { try { String globalName = "rmi//127.0.0.1:1099/hello"; RemoteInterface remoteObj = (RemoteInterface)Naming.lookup(globalName); System.out.println(remoteObj.SayHello()); } catch(Exception e) { System.out.println(e.getMessage()); }
I don't understand the reason why I must ude the interface RemoteInterface to do the lookup? Can't I use the HelloStub class, which is the real remote obj?
Thanks bye.
RemoteInterfaceto allow a level of abstraction - this way both sides (Client and Server) don't have to know anything about each other apart from the fact that both have to implementRemoteInterface- Germann Arlington