Chapter 4

Exporting an Object


Universal TeacherThere are two choices when creating a remote object:

Extend UnicastRemoteObject class, or
Export the object by using one of the static functions of UnicastRemoteObject.

The central theme of this chapter is how to explicitly export a remote object. The source code needed for this example is stored in the examples\Greater directory. The "Greater" directory contains the following files:

  • Compile.bat
  • Rmicompile.bat
  • RunServer.bat
  • RunClient.bat


Universal TeacherServer Architecture

The design of the server is simple. The server starts a registry service, registers itself with the registry, and exports a method.

Creating Remote Interface

The GreaterInterface contains only one method that returns a string object. The getGreater() method compares two given numbers and returns the larger number.

Listing 4.1 (Complete code)

import java.rmi.*;

//server interface
public interface GreaterInterface 
	extends Remote{

//method used to compare two given numbers		
public String getGreater(int one,int two)
	throws RemoteException;


RMI BOOK MAIN PAGE                Top

Copyright © 2001