SlideShare a Scribd company logo
1 of 11
Download to read offline
Remote Method
               Invocation




“The network is the computer”
 Consider the following program organization:

          method call
       SomeClass             AnotherClass
                          returned object
       computer 1            computer 2

 If the network is the computer, we ought
 to be able to put the two classes on
 different computers
 RMI is one technology that makes this possible
Java Remote Object Invocation (RMI)

   RMI allows programmers to execute remote function
   class using the same semantics as local functions
   calls.

    Local Machine (Client)                Remote Machine (Server)

    SampleServer remoteObject;
    int s;
    …

    s = remoteObject.sum(1,2);
                                 1,2
                                          public int sum(int a,int b)
                                          {
                                   3      }
                                               return a + b;


    System.out.println(s);




What is needed for RMI
  Java makes RMI (Remote Method Invocation)
  fairly easy, but there are some extra steps
  To send a message to a remote “server object,”
    The “client object” has to find the object
        Do this by looking it up in a registry
    The client object then has to marshal the parameters
    (prepare them for transmission)
        Java requires Serializable parameters
        The server object has to unmarshal its parameters, do its
        computation, and marshal its response
    The client object has to unmarshal the response
  Much of this is done for you by special software
Terminology
 A remote object is an object on another computer
 The client object is the object making the request
 (sending a message to the other object)
 The server object is the object receiving the request
 As usual, “client” and “server” can easily trade roles
 (each can make requests of the other)
 The rmiregistry is a special server that looks up objects
 by name
    Hopefully, the name is unique!
 rmic is a special compiler for creating stub (client) and
 skeleton (server) classes




RMI Components

  RMI registry
    Each remote object needs to register their location
    RMI clients find remote objects via the lookup service

  Server hosting a remote object
    Construct an implementation of the object
    Provide access to methods via skeleton
    Register the object to the RMI registry                RMIRegistry


  Client using a remote object
    Ask registry for location of the object
                                                       2. lookup        1. bind
    Construct stub
    Call methods via the object’s stub
                                                              3. call
                                              client                              server
Interfaces
 Interfaces define behavior
 Classes define implementation

 Therefore,
   In order to use a remote object, the client must know
   its behavior (interface), but does not need to know its
   implementation (class)
   In order to provide an object, the server must know
   both its interface (behavior) and its class
   (implementation)
 In short,
   The interface must be available to both client and
   server
   The class should only be on the server




Classes
 A Remote class is one whose instances can be
 accessed remotely
   On the computer where it is defined, instances of this
   class can be accessed just like any other object
   On other computers, the remote object can be
   accessed via object handles
 A Serializable class is one whose instances can
 be marshaled (turned into a linear sequence of
 bits)
   Serializable objects can be transmitted from one
   computer to another
Conditions for serializability

 If an object is to be serialized:
   The class must be declared as public
   The class must implement Serializable
   The class must have a no-argument
   constructor
   All fields of the class must be
   serializable: either primitive types or
   serializable objects




Remote interfaces and class
 A Remote class has two parts:
   The interface (used by both client and server):
     Must be public
     Must extend the interface java.rmi.Remote
     Every method in the interface must declare that it
     throws java.rmi.RemoteException (other
     exceptions may also be thrown)
   The class itself (used only by the server):
     Must implement a Remote interface
     Should extend
     java.rmi.server.UnicastRemoteObject
     May have locally accessible methods that are not
     in its Remote interface
Remote vs. Serializable
 A Remote object lives on another computer (such as the
 Server)
    You can send messages to a Remote object and get responses
    back from the object
    All you need to know about the Remote object is its interface
    Remote objects don’t pose much of a security issue
 You can transmit a copy of a Serializable object between
 computers
    The receiving object needs to know how the object is
    implemented; it needs the class as well as the interface
    There is a way to transmit the class definition
    Accepting classes does pose a security issue




RMI Architecture
                                                   Remote Machine
   The server must first bind
                                                                    bind
   its name to the registry                  RMI Server

   The client lookup the                                               Registry
   server name in the                            skeleton

   registry to establish
   remote references.                   return              call              lookup

   The Stub serializing the
   parameters to skeleton,                        stub
   the skeleton invoking the
   remote method and                         RMI Client
   serializing the result back
   to the stub.                                     Local Machine
The Stub and Skeleton
                                      call




                                                    skeleton
                        Stub
          RMI Client                                           RMI Server
                                     return


     Each remote object has two interfaces
        Client interface – a stub/proxy of the object
        Server interface – a skeleton of the object
     When a client invokes a remote method, the call is first
     forwarded to stub.
     The stub is responsible for sending the remote call over to the
     server-side skeleton
     The stub opening a socket to the remote server, marshaling the
     object parameters and forwarding the data stream to the
     skeleton.
     A skeleton contains a method that receives the remote calls,
     unmarshals the parameters, and invokes the actual remote
     object implementation.




Steps of Using RMI

1.   Create Service Interface
2.   Implement Service Interface
3.   Create Stub and Skeleton Classes
4.   Create RMI Server
5.   Create RMI Client
1. Defining RMI Service Interface

     Declare an Interface that extends
     java.rmi.Remote
       Stub, skeleton, and implementation will
       implement this interface
       Client will access methods declared in the
       interface
     Example
 public interface RMILightBulb extends java.rmi.Remote {
   public void on ()     throws java.rmi.RemoteException;
   public void off()     throws java.rmi.RemoteException;
   public boolean isOn() throws java.rmi.RemoteException;
 }




2. Implementing RMI Service Interface
     Provide concrete implementation for each methods defined in the
     interface
     The class that implement the service should extend
     UnicastRemoteObject
     Every remotely available method must throw a RemoteException
     (because connections can fail)
 public class RMILightBulbImpl extends java.rmi.server.UnicastRemoteObject
     implements RMILightBulb
 {
     public RMILightBulbImpl() throws java.rmi.RemoteException
     {setBulb(false);}
     private boolean lightOn;
     public void on() throws java.rmi.RemoteException { setBulb (true); }
     public void off() throws java.rmi.RemoteException {setBulb (false);}
     public boolean isOn() throws java.rmi.RemoteException
     { return getBulb(); }
     public void setBulb (boolean value) { lightOn = value; }
     public boolean getBulb () { return lightOn; }
 }
3. Generating Stub & Skeleton Classes

   The class that implements the remote
   object should be compiled as usual
   Then, it should be compiled with rmic:
   Example:
      rmic RMILightBulbImpl
      creates the classes:
         RMILightBulbImpl_Stub.class
           Client stub
         RMILightBulbImpl_Skeleton.class
           Server skeleton
   These classes do the actual communication




4. Creating RMI Server

     Create an instance of the service implementation
     Register with the RMI registry (binding)
 import java.rmi.*;
 import java.rmi.server.*;
 public class LightBulbServer {
  public static void main(String args[]) {
   try {
    RMILightBulbImpl bulbService = new RMILightBulbImpl();
    RemoteRef location = bulbService.getRef();
    System.out.println (location.remoteToString());
    String registry = "localhost";
    if (args.length >=1) {
      registry = args[0];
    }
    String registration = "rmi://" + registry + "/RMILightBulb";
    Naming.rebind( registration, bulbService );
  } catch (Exception e) { System.err.println ("Error - " + e); } } }
5. Creating RMI Client

     Obtain a reference to the remote interface
     Invoke desired methods on the reference
 import java.rmi.*;
 public class LightBulbClient {
   public static void main(String args[]) {
     try { String registry = "localhost";
      if (args.length >=1) { registry = args[0]; }
      String registration = "rmi://" + registry + "/RMILightBulb";
      Remote remoteService = Naming.lookup ( registration );
      RMILightBulb bulbService = (RMILightBulb) remoteService;
      bulbService.on();
      System.out.println ("Bulb state : " + bulbService.isOn() );
      System.out.println ("Invoking bulbservice.off()");
      bulbService.off();
      System.out.println ("Bulb state : " + bulbService.isOn() );
     } catch (NotBoundException nbe) {
      System.out.println ("No light bulb service available in registry!");
     } catch (RemoteException re) { System.out.println ("RMI - " + re);
     } catch (Exception e) { System.out.println ("Error - " + e); }
   }
 }




Steps of Running RMI

   Make the classes available in the server host's,
   registry host's, and client host's classpath
      Copy, if necessary
   Start the registry
      rmiregistry
   Start the server
      java LightBulbServer reg-hostname
   Start the client
      java LightBulbClient reg-hostname
References
 Java Network Programming and Distributed Computing, David Reilly & Michael
 Reilly, Addison Wesley.
 CS587x – Remote Method Invocation, Ying Cai, Department of Computer Science,
 Iowa State University.

More Related Content

What's hot

What's hot (20)

Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
 
Java rmi
Java rmiJava rmi
Java rmi
 
A Short Java RMI Tutorial
A Short Java RMI TutorialA Short Java RMI Tutorial
A Short Java RMI Tutorial
 
javarmi
javarmijavarmi
javarmi
 
Java RMI Detailed Tutorial
Java RMI Detailed TutorialJava RMI Detailed Tutorial
Java RMI Detailed Tutorial
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
Rmi
RmiRmi
Rmi
 
Rmi ppt
Rmi pptRmi ppt
Rmi ppt
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
 
Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVA
 
Rmi
RmiRmi
Rmi
 
remote method invocation
remote method invocationremote method invocation
remote method invocation
 
Rmi presentation
Rmi presentationRmi presentation
Rmi presentation
 
Java rmi tutorial
Java rmi tutorialJava rmi tutorial
Java rmi tutorial
 
Distributes objects and Rmi
Distributes objects and RmiDistributes objects and Rmi
Distributes objects and Rmi
 
Java RMI
Java RMIJava RMI
Java RMI
 

Viewers also liked

Bookings and Reservations
Bookings and ReservationsBookings and Reservations
Bookings and ReservationsCentrecom
 
4 quan ly-nguoi_dung
4 quan ly-nguoi_dung4 quan ly-nguoi_dung
4 quan ly-nguoi_dungvantinhkhuc
 
Going social with collaborative online ideations
Going social with collaborative online ideationsGoing social with collaborative online ideations
Going social with collaborative online ideationsFrank Hatzack
 
Skinny for Summer? How about Fit for Life
Skinny for Summer? How about Fit for LifeSkinny for Summer? How about Fit for Life
Skinny for Summer? How about Fit for LifeCindy McAsey
 
The Millennial Shift: Financial Services and the Digial Generation Study Preview
The Millennial Shift: Financial Services and the Digial Generation Study PreviewThe Millennial Shift: Financial Services and the Digial Generation Study Preview
The Millennial Shift: Financial Services and the Digial Generation Study PreviewCorporate Insight
 
UNHI Creative Works Symposium Session: Copyright Fair Use
UNHI Creative Works Symposium Session: Copyright Fair UseUNHI Creative Works Symposium Session: Copyright Fair Use
UNHI Creative Works Symposium Session: Copyright Fair UseUNHInnovation
 
UNHI Creative Works Symposium Session: Deconstructing a Cpyright License
UNHI Creative Works Symposium Session: Deconstructing a Cpyright LicenseUNHI Creative Works Symposium Session: Deconstructing a Cpyright License
UNHI Creative Works Symposium Session: Deconstructing a Cpyright LicenseUNHInnovation
 
Dello elena
Dello elenaDello elena
Dello elenaklepa.ru
 
Security overview
Security overviewSecurity overview
Security overviewvantinhkhuc
 
Новости недвижимости майами за Июль 2016
Новости недвижимости майами за Июль 2016 Новости недвижимости майами за Июль 2016
Новости недвижимости майами за Июль 2016 The Reznik Group
 
Etude Ramey et al, 2002
Etude Ramey et al, 2002Etude Ramey et al, 2002
Etude Ramey et al, 2002auroreape
 
La sabiesa del vell
La sabiesa del vellLa sabiesa del vell
La sabiesa del vellPilar Morey
 
Marilyn Monroe Collection
Marilyn Monroe CollectionMarilyn Monroe Collection
Marilyn Monroe CollectionTerry Gaouette
 

Viewers also liked (20)

9 bash
9 bash9 bash
9 bash
 
Bookings and Reservations
Bookings and ReservationsBookings and Reservations
Bookings and Reservations
 
4 quan ly-nguoi_dung
4 quan ly-nguoi_dung4 quan ly-nguoi_dung
4 quan ly-nguoi_dung
 
Khalifa
KhalifaKhalifa
Khalifa
 
Going social with collaborative online ideations
Going social with collaborative online ideationsGoing social with collaborative online ideations
Going social with collaborative online ideations
 
Skinny for Summer? How about Fit for Life
Skinny for Summer? How about Fit for LifeSkinny for Summer? How about Fit for Life
Skinny for Summer? How about Fit for Life
 
The Millennial Shift: Financial Services and the Digial Generation Study Preview
The Millennial Shift: Financial Services and the Digial Generation Study PreviewThe Millennial Shift: Financial Services and the Digial Generation Study Preview
The Millennial Shift: Financial Services and the Digial Generation Study Preview
 
UNHI Creative Works Symposium Session: Copyright Fair Use
UNHI Creative Works Symposium Session: Copyright Fair UseUNHI Creative Works Symposium Session: Copyright Fair Use
UNHI Creative Works Symposium Session: Copyright Fair Use
 
UNHI Creative Works Symposium Session: Deconstructing a Cpyright License
UNHI Creative Works Symposium Session: Deconstructing a Cpyright LicenseUNHI Creative Works Symposium Session: Deconstructing a Cpyright License
UNHI Creative Works Symposium Session: Deconstructing a Cpyright License
 
Dello elena
Dello elenaDello elena
Dello elena
 
Ajax
AjaxAjax
Ajax
 
Security overview
Security overviewSecurity overview
Security overview
 
Varför appar?
Varför appar?Varför appar?
Varför appar?
 
Новости недвижимости майами за Июль 2016
Новости недвижимости майами за Июль 2016 Новости недвижимости майами за Июль 2016
Новости недвижимости майами за Июль 2016
 
Etude Ramey et al, 2002
Etude Ramey et al, 2002Etude Ramey et al, 2002
Etude Ramey et al, 2002
 
La sabiesa del vell
La sabiesa del vellLa sabiesa del vell
La sabiesa del vell
 
Sharp advertising
Sharp advertisingSharp advertising
Sharp advertising
 
Educazione fisica
Educazione fisicaEducazione fisica
Educazione fisica
 
1 linux
1 linux1 linux
1 linux
 
Marilyn Monroe Collection
Marilyn Monroe CollectionMarilyn Monroe Collection
Marilyn Monroe Collection
 

Similar to Rmi (20)

Distributed objects
Distributed objectsDistributed objects
Distributed objects
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
DS
DSDS
DS
 
Rmi
RmiRmi
Rmi
 
Java RMI
Java RMIJava RMI
Java RMI
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Remote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programmingRemote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programming
 
Rmi3
Rmi3Rmi3
Rmi3
 
ADB Lab Manual.docx
ADB Lab Manual.docxADB Lab Manual.docx
ADB Lab Manual.docx
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 
Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01
 
Rmi
RmiRmi
Rmi
 
Rmi
RmiRmi
Rmi
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
 
#4 (Remote Method Invocation)
#4 (Remote Method Invocation)#4 (Remote Method Invocation)
#4 (Remote Method Invocation)
 
Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
 
Java rmi
Java rmiJava rmi
Java rmi
 
17rmi
17rmi17rmi
17rmi
 
remote method invocation
remote method invocationremote method invocation
remote method invocation
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 

More from vantinhkhuc (20)

Url programming
Url programmingUrl programming
Url programming
 
Servlets intro
Servlets introServlets intro
Servlets intro
 
Servlet sessions
Servlet sessionsServlet sessions
Servlet sessions
 
Md5
Md5Md5
Md5
 
Lecture17
Lecture17Lecture17
Lecture17
 
Lecture11 b
Lecture11 bLecture11 b
Lecture11 b
 
Lecture10
Lecture10Lecture10
Lecture10
 
Lecture9
Lecture9Lecture9
Lecture9
 
Lecture6
Lecture6Lecture6
Lecture6
 
Jsse
JsseJsse
Jsse
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
Jsp examples
Jsp examplesJsp examples
Jsp examples
 
Jpa
JpaJpa
Jpa
 
Ejb examples
Ejb examplesEjb examples
Ejb examples
 
Corba
CorbaCorba
Corba
 
Ejb intro
Ejb introEjb intro
Ejb intro
 
Chc6b0c6a1ng 12
Chc6b0c6a1ng 12Chc6b0c6a1ng 12
Chc6b0c6a1ng 12
 
Ch06
Ch06Ch06
Ch06
 
Bai4
Bai4Bai4
Bai4
 
Ajas11 alok
Ajas11 alokAjas11 alok
Ajas11 alok
 

Rmi

  • 1. Remote Method Invocation “The network is the computer” Consider the following program organization: method call SomeClass AnotherClass returned object computer 1 computer 2 If the network is the computer, we ought to be able to put the two classes on different computers RMI is one technology that makes this possible
  • 2. Java Remote Object Invocation (RMI) RMI allows programmers to execute remote function class using the same semantics as local functions calls. Local Machine (Client) Remote Machine (Server) SampleServer remoteObject; int s; … s = remoteObject.sum(1,2); 1,2 public int sum(int a,int b) { 3 } return a + b; System.out.println(s); What is needed for RMI Java makes RMI (Remote Method Invocation) fairly easy, but there are some extra steps To send a message to a remote “server object,” The “client object” has to find the object Do this by looking it up in a registry The client object then has to marshal the parameters (prepare them for transmission) Java requires Serializable parameters The server object has to unmarshal its parameters, do its computation, and marshal its response The client object has to unmarshal the response Much of this is done for you by special software
  • 3. Terminology A remote object is an object on another computer The client object is the object making the request (sending a message to the other object) The server object is the object receiving the request As usual, “client” and “server” can easily trade roles (each can make requests of the other) The rmiregistry is a special server that looks up objects by name Hopefully, the name is unique! rmic is a special compiler for creating stub (client) and skeleton (server) classes RMI Components RMI registry Each remote object needs to register their location RMI clients find remote objects via the lookup service Server hosting a remote object Construct an implementation of the object Provide access to methods via skeleton Register the object to the RMI registry RMIRegistry Client using a remote object Ask registry for location of the object 2. lookup 1. bind Construct stub Call methods via the object’s stub 3. call client server
  • 4. Interfaces Interfaces define behavior Classes define implementation Therefore, In order to use a remote object, the client must know its behavior (interface), but does not need to know its implementation (class) In order to provide an object, the server must know both its interface (behavior) and its class (implementation) In short, The interface must be available to both client and server The class should only be on the server Classes A Remote class is one whose instances can be accessed remotely On the computer where it is defined, instances of this class can be accessed just like any other object On other computers, the remote object can be accessed via object handles A Serializable class is one whose instances can be marshaled (turned into a linear sequence of bits) Serializable objects can be transmitted from one computer to another
  • 5. Conditions for serializability If an object is to be serialized: The class must be declared as public The class must implement Serializable The class must have a no-argument constructor All fields of the class must be serializable: either primitive types or serializable objects Remote interfaces and class A Remote class has two parts: The interface (used by both client and server): Must be public Must extend the interface java.rmi.Remote Every method in the interface must declare that it throws java.rmi.RemoteException (other exceptions may also be thrown) The class itself (used only by the server): Must implement a Remote interface Should extend java.rmi.server.UnicastRemoteObject May have locally accessible methods that are not in its Remote interface
  • 6. Remote vs. Serializable A Remote object lives on another computer (such as the Server) You can send messages to a Remote object and get responses back from the object All you need to know about the Remote object is its interface Remote objects don’t pose much of a security issue You can transmit a copy of a Serializable object between computers The receiving object needs to know how the object is implemented; it needs the class as well as the interface There is a way to transmit the class definition Accepting classes does pose a security issue RMI Architecture Remote Machine The server must first bind bind its name to the registry RMI Server The client lookup the Registry server name in the skeleton registry to establish remote references. return call lookup The Stub serializing the parameters to skeleton, stub the skeleton invoking the remote method and RMI Client serializing the result back to the stub. Local Machine
  • 7. The Stub and Skeleton call skeleton Stub RMI Client RMI Server return Each remote object has two interfaces Client interface – a stub/proxy of the object Server interface – a skeleton of the object When a client invokes a remote method, the call is first forwarded to stub. The stub is responsible for sending the remote call over to the server-side skeleton The stub opening a socket to the remote server, marshaling the object parameters and forwarding the data stream to the skeleton. A skeleton contains a method that receives the remote calls, unmarshals the parameters, and invokes the actual remote object implementation. Steps of Using RMI 1. Create Service Interface 2. Implement Service Interface 3. Create Stub and Skeleton Classes 4. Create RMI Server 5. Create RMI Client
  • 8. 1. Defining RMI Service Interface Declare an Interface that extends java.rmi.Remote Stub, skeleton, and implementation will implement this interface Client will access methods declared in the interface Example public interface RMILightBulb extends java.rmi.Remote { public void on () throws java.rmi.RemoteException; public void off() throws java.rmi.RemoteException; public boolean isOn() throws java.rmi.RemoteException; } 2. Implementing RMI Service Interface Provide concrete implementation for each methods defined in the interface The class that implement the service should extend UnicastRemoteObject Every remotely available method must throw a RemoteException (because connections can fail) public class RMILightBulbImpl extends java.rmi.server.UnicastRemoteObject implements RMILightBulb { public RMILightBulbImpl() throws java.rmi.RemoteException {setBulb(false);} private boolean lightOn; public void on() throws java.rmi.RemoteException { setBulb (true); } public void off() throws java.rmi.RemoteException {setBulb (false);} public boolean isOn() throws java.rmi.RemoteException { return getBulb(); } public void setBulb (boolean value) { lightOn = value; } public boolean getBulb () { return lightOn; } }
  • 9. 3. Generating Stub & Skeleton Classes The class that implements the remote object should be compiled as usual Then, it should be compiled with rmic: Example: rmic RMILightBulbImpl creates the classes: RMILightBulbImpl_Stub.class Client stub RMILightBulbImpl_Skeleton.class Server skeleton These classes do the actual communication 4. Creating RMI Server Create an instance of the service implementation Register with the RMI registry (binding) import java.rmi.*; import java.rmi.server.*; public class LightBulbServer { public static void main(String args[]) { try { RMILightBulbImpl bulbService = new RMILightBulbImpl(); RemoteRef location = bulbService.getRef(); System.out.println (location.remoteToString()); String registry = "localhost"; if (args.length >=1) { registry = args[0]; } String registration = "rmi://" + registry + "/RMILightBulb"; Naming.rebind( registration, bulbService ); } catch (Exception e) { System.err.println ("Error - " + e); } } }
  • 10. 5. Creating RMI Client Obtain a reference to the remote interface Invoke desired methods on the reference import java.rmi.*; public class LightBulbClient { public static void main(String args[]) { try { String registry = "localhost"; if (args.length >=1) { registry = args[0]; } String registration = "rmi://" + registry + "/RMILightBulb"; Remote remoteService = Naming.lookup ( registration ); RMILightBulb bulbService = (RMILightBulb) remoteService; bulbService.on(); System.out.println ("Bulb state : " + bulbService.isOn() ); System.out.println ("Invoking bulbservice.off()"); bulbService.off(); System.out.println ("Bulb state : " + bulbService.isOn() ); } catch (NotBoundException nbe) { System.out.println ("No light bulb service available in registry!"); } catch (RemoteException re) { System.out.println ("RMI - " + re); } catch (Exception e) { System.out.println ("Error - " + e); } } } Steps of Running RMI Make the classes available in the server host's, registry host's, and client host's classpath Copy, if necessary Start the registry rmiregistry Start the server java LightBulbServer reg-hostname Start the client java LightBulbClient reg-hostname
  • 11. References Java Network Programming and Distributed Computing, David Reilly & Michael Reilly, Addison Wesley. CS587x – Remote Method Invocation, Ying Cai, Department of Computer Science, Iowa State University.