Client Implementation

The client receives a stub and can make remote invocations through the stub. The client has no idea that the object is activatable or running as a standard UnicastRemoteObject.

The client in this example remotely invokes the sayHello() method in order to get the string "Hello World!". Here is the code:

Listing 13.4 Client.java

import java.rmi.*;
public class Client {
public static void main(String args[]) {

  //Installing a security manager
  System.setSecurityManager(new RMISecurityManager());
  try {

//get a reference to the remote reference LazyInterface li = (LazyInterface)Naming.lookup("LazyServer"); System.out.println("Calling the server"); //calling the remote method String result = (String)li.sayHello(); System.out.println(result); } catch (Exception e) { System.out.println(e.getMessage()); } } }

The client gets a reference to the remote object implementation from the server(s) rmiregistry and calls the remote method.

 

 

 

RMI BOOK MAIN PAGE                Top

  
Copyright © 2001 www.universalteacher.com