Java Reference
In-Depth Information
/** Constructor **/
public RMIExampleClient () {
// Create and install a security manager.
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
// Get a reference to the remote server named
// rmi-example-server.
RMIExampleInterface rmi - example - server = null;
try {
// Find the server.
String server - name =" //localhost:3001/rmi-example-server " ;
System.err.println (
" RMIExampleClient: looking up server " +server - name
);
rmi - example - server =
(RMIExampleInterface) Naming.lookup (server - name);
System.err.println ("RMIExampleClient: found it!");
} // try
catch (MalformedURLException mue) {
System.err.println (mue);
}
catch (NotBoundException nbe) {
System.err.println (nbe);
}
catch (RemoteException re) {
System.err.println (re);
}
if (rmi - example - server == null) {
System.err.println ("\nEXITING BECAUSE OF FAILURE");
System.exit (1);
}
// Test method1.
System.err.println (
"Calling remote method1 which should echo the string "
+ "'hello from client'"
);
try {
rmi - example - server.method1 ( " hello from client " );
}
catch (RemoteException re) {
System.err.println (re);
}
// Test the add method.
 
Search WWH ::




Custom Search