Java Reference
In-Depth Information
System.out.println("Binding complete…\n");
4. Create the client process.
The client obtains a reference to the remote object from the registry. It does this by
using method lookup of class Naming , supplying as an argument to this method the
same URL that the server did when binding the object reference to the object's
name in the registry. Since lookup returns a Remote reference, this reference must
be typecast into an Hello reference ( not an HelloImpl reference!). Once the Hello
reference has been obtained, it can be used to call the solitary method that was made
available in the interface.
import java.rmi.*;
public class HelloClient
private static fi nal String HOST = "localhost";
public static void main(String[] args)
//Obtain a reference to the object from the
//registry and typecast it into the appropriate
Hello greeting =
+ HOST + "/Hello");
//Use the above reference to invoke the remote
//object's method…
System.out.println("Message received: "
+ greeting.getGreeting());
catch(ConnectException conEx)
"Unable to connect to server!");
catch(Exception ex)
Search WWH ::

Custom Search