OO Programming in Java

Class 10 Material


Remote Method Invocation transcends the normal client/server model of distributed computing by using the Remote Object model.

Clients invoke methods from remote objects exactly the same as if the objects were local ...... after things are set up.

Steps to develop an RMI application (See Note 1)

Step 1

Create an interface that extends the java.rmi.Remote interface. This interface defines the methods that will be accessed remotely by the client. These methods must throw a java.rmi.RemoteException

Step 2

Define a subclass of java.rmi.server.UnicastRemoteObject that implements your remote object.. Note that other than declaring its remote methods to throw RemoteException objects, the remote object does not need to do anything special to allow its methods to be invoked remotely.

Step 3

Write a server program that creates an instance of your remote object. Export the object by registring it with a registry service. (rmiregistry program)

Step 4

After compiling the program run rmic to generate stub and skeleton classes for the remote object. Stubs are used by the client, Skeletons by the server

Step 5

Run the rmiregistry program

Step 6

Write the client application. Use Naming class to lookup a reference to the remote object. Now methods may be used in the remote object.

Step 7

Start the server and client and enjoy.  



PageTurnerServer Code

PageTurnerClient Code

Note 1. Portions of the above descriptions are taken from Java Examples in a Nutshell by David Flanagan.