RMI generates a client-side file with a main() method that looks like the following example:
public static void main (String[] args) { System.setSecurityManager (new RMISecurityManager()); }
To complete your client class, you must add a lookup() call that returns a reference to the correct RMI server. You can use the reference to invoke server-side methods.
To add a lookup() call:
You need to know which RMI registry the server is registered with. In a large development effort, the server might be under control of a system administrator or another developer. If you are doing all the development work, you can start the server yourself.
A service node with the same name as the remote object appears under the registry node.
The main() method should resemble the code.
The object returned by the lookup is a proxy for the RMI server. You can invoke methods on it. Use code similar to the example:
obj.sayHello();
Your completed main method should look like this:
public static void main (String[] args) { System.setSecurityManager (new RMISecurityManager()); try { Hello obj = (Hello) Naming.lookup ("//localhost:1099/Remote"); obj.sayHello(); } catch (Exception ex) { ex.printStackTrace(); }
See also | |
---|---|
Generating a Client-side File
Compiling and Running a Client-side File |