SlideShare a Scribd company logo
By
Om Nishant
 080911216
Java remote method invocation
 The Java Remote Method Invocation Application
  Programming Interface (API), or Java RMI, is a Java
  application programming interface that performs the
  object-oriented equivalent of remote procedure calls
  (RPC).
 Typically comprise 2 separate programs:-
   Client
   Server
 A remote interface specifies the methods that can be
 invoked remotely by a client
RMI Server Interface
import java.rmi.Remote;
import java.rmi.RemoteException;
/*interface must extend Remote to enable access from
another JVM
The methods being remote methods can throw Remote
Exception */

public interface RmiServerIntf extends Remote {
  public String getMessage() throws RemoteException;
/*This is the method implemented by server and
accessed by client*/
}
Implementing the interface
 An RMI server program needs to create the initial
  remote objects and export them to the RMI runtime

 The setup procedure should do the following:
    Create and install a security manager
    Create and export one or more remote objects
    Register at least one remote object with the RMI
     registry (or with another naming service
RMI Server Program
import java.rmi.Naming;
import java.rmi.registry.*;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;

//public class classname implements remote-interface
public class RmiServer extends UnicastRemoteObject implements RmiServerIntf {

  public static final String MESSAGE = "Hello world";

   public RmiServer() throws RemoteException {
  //constructor defn }

  public String getMessage() {
//Todo code for the remote method(s)
     return MESSAGE;
  }
public static void main(String args[]) {

//main   method is used to create an instance and make it available to clients.


//Write the todo code here


    System.out.println("RMI server started");

    // Create and install a security manager

    if (System.getSecurityManager() == null) {
       System.setSecurityManager(new RMISecurityManager());
       System.out.println("Security manager installed.");
    } else {
       System.out.println("Security manager already exists.");
    }
try {

//special exception handler for registry creation
//Registry used for naming services

        LocateRegistry.createRegistry(1099);
        System.out.println("java RMI registry created.");
     }
    catch (RemoteException e) {

        //do nothing, error means registry already exists
        System.out.println("java RMI registry already exists.");
    }
try {
             //Instantiate RmiServer
            //(ClassNAme)UnicastRemoteObject.exportObject(object1, portno);
             RmiServer obj = new RmiServer();

             // Bind this object instance to the name "RmiServer“

             Naming.rebind("//localhost/RmiServer", obj);


             System.out.println("PeerServer bound in registry");

       }
    catch (Exception e) {

             System.err.println("RMI server exception:" + e);
             e.printStackTrace();
        }
}
}
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;

public class RmiClient {
  // "obj" is the reference of the remote object
  RmiServerIntf obj = null;

  public String getMessage() {
    try {
       obj = (RmiServerIntf)Naming.lookup("//localhost/RmiServer");
       return obj.getMessage();
    } catch (Exception e) {
       System.err.println("RmiClient exception: " + e);
       return e.getMessage();
    }
  }
public static void main(String args[]) {

        // Create and install a security manager

        if (System.getSecurityManager() == null) {

            System.setSecurityManager(new RMISecurityManager());

        }

        RmiClient cli = new RmiClient();

        System.out.println(cli.getMessage());
    }
}
Implementation:
 Compile the source code files
    javac filename
 Create the stub for client and skeleton for server
   rmic serverfilename
 Start the server
    rmiregistry
 Ensure security permits are in order
 Run the server and client files
Common sources of errors
 Before running the server, make sure you have an
  instance of rmiregistry running on the server
 Make sure that your CLASSPATH variable is empty
 Not having a suitable security policy
 Mixing Java versions
Java remote method invocation

More Related Content

PPS
Java rmi
PPT
PDF
Remote Method Invocation in JAVA
PPTX
PDF
Java rmi
PPT
A Short Java RMI Tutorial
PPSX
Java rmi
PPT
Java rmi
Remote Method Invocation in JAVA
Java rmi
A Short Java RMI Tutorial
Java rmi

What's hot (19)

PPTX
Introduction To Rmi
PPTX
Java RMI(Remote Method Invocation)
PPTX
Remote Method Invocation (Java RMI)
PPTX
PPTX
Remote method invocation
PPTX
Remote Method Innovation (RMI) In JAVA
PPTX
Java RMI
PPTX
Rmi presentation
PDF
Rmi ppt-2003
PPT
Remote Method Invocation
PDF
Remote Method Invocation
PPT
Distributed Programming using RMI
PPTX
Rmi architecture
PPTX
Java RMI Presentation
PDF
Java rmi tutorial
PDF
Remote Method Invocation (RMI)
PPTX
Java RMI
PPS
Java rmi example program with code
Introduction To Rmi
Java RMI(Remote Method Invocation)
Remote Method Invocation (Java RMI)
Remote method invocation
Remote Method Innovation (RMI) In JAVA
Java RMI
Rmi presentation
Rmi ppt-2003
Remote Method Invocation
Remote Method Invocation
Distributed Programming using RMI
Rmi architecture
Java RMI Presentation
Java rmi tutorial
Remote Method Invocation (RMI)
Java RMI
Java rmi example program with code
Ad

Similar to Java remote method invocation (20)

PPT
Distributed Objects and JAVA
PDF
JavaRMI, JAVA RPC , INTRO , DESCRIPTION , EXPLAINED.pdf
DOCX
Remote Method Invocation
DOCX
ADB Lab Manual.docx
PPTX
Remote method invocation
PPT
Java RMI
PDF
Remote Method Invocation, Advanced programming
DOCX
remote method invocation
PPT
PDF
Run rmi
PDF
17rmi
PDF
Remote Method Invocation
PDF
Introduction to Remote Method Invocation (RMI)
PDF
PDF
RMI Java Programming Lab Manual 2019
PPTX
Remote method invocatiom
PDF
java TM rmi The Remote Method Invocation Guide 1st Edition Esmond Pitt
Distributed Objects and JAVA
JavaRMI, JAVA RPC , INTRO , DESCRIPTION , EXPLAINED.pdf
Remote Method Invocation
ADB Lab Manual.docx
Remote method invocation
Java RMI
Remote Method Invocation, Advanced programming
remote method invocation
Run rmi
17rmi
Remote Method Invocation
Introduction to Remote Method Invocation (RMI)
RMI Java Programming Lab Manual 2019
Remote method invocatiom
java TM rmi The Remote Method Invocation Guide 1st Edition Esmond Pitt
Ad

Recently uploaded (20)

PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
Institutional Correction lecture only . . .
PPTX
Cell Structure & Organelles in detailed.
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
Lesson notes of climatology university.
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Classroom Observation Tools for Teachers
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Abdominal Access Techniques with Prof. Dr. R K Mishra
Anesthesia in Laparoscopic Surgery in India
FourierSeries-QuestionsWithAnswers(Part-A).pdf
RMMM.pdf make it easy to upload and study
Institutional Correction lecture only . . .
Cell Structure & Organelles in detailed.
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Pharma ospi slides which help in ospi learning
01-Introduction-to-Information-Management.pdf
Cell Types and Its function , kingdom of life
Lesson notes of climatology university.
human mycosis Human fungal infections are called human mycosis..pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
A systematic review of self-coping strategies used by university students to ...
Classroom Observation Tools for Teachers
Chinmaya Tiranga quiz Grand Finale.pdf

Java remote method invocation

  • 2. Java remote method invocation  The Java Remote Method Invocation Application Programming Interface (API), or Java RMI, is a Java application programming interface that performs the object-oriented equivalent of remote procedure calls (RPC).  Typically comprise 2 separate programs:-  Client  Server  A remote interface specifies the methods that can be invoked remotely by a client
  • 3. RMI Server Interface import java.rmi.Remote; import java.rmi.RemoteException; /*interface must extend Remote to enable access from another JVM The methods being remote methods can throw Remote Exception */ public interface RmiServerIntf extends Remote { public String getMessage() throws RemoteException; /*This is the method implemented by server and accessed by client*/ }
  • 4. Implementing the interface  An RMI server program needs to create the initial remote objects and export them to the RMI runtime  The setup procedure should do the following:  Create and install a security manager  Create and export one or more remote objects  Register at least one remote object with the RMI registry (or with another naming service
  • 5. RMI Server Program import java.rmi.Naming; import java.rmi.registry.*; import java.rmi.RemoteException; import java.rmi.RMISecurityManager; import java.rmi.server.UnicastRemoteObject; //public class classname implements remote-interface public class RmiServer extends UnicastRemoteObject implements RmiServerIntf { public static final String MESSAGE = "Hello world"; public RmiServer() throws RemoteException { //constructor defn } public String getMessage() { //Todo code for the remote method(s) return MESSAGE; }
  • 6. public static void main(String args[]) { //main method is used to create an instance and make it available to clients. //Write the todo code here System.out.println("RMI server started"); // Create and install a security manager if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); System.out.println("Security manager installed."); } else { System.out.println("Security manager already exists."); }
  • 7. try { //special exception handler for registry creation //Registry used for naming services LocateRegistry.createRegistry(1099); System.out.println("java RMI registry created."); } catch (RemoteException e) { //do nothing, error means registry already exists System.out.println("java RMI registry already exists."); }
  • 8. try { //Instantiate RmiServer //(ClassNAme)UnicastRemoteObject.exportObject(object1, portno); RmiServer obj = new RmiServer(); // Bind this object instance to the name "RmiServer“ Naming.rebind("//localhost/RmiServer", obj); System.out.println("PeerServer bound in registry"); } catch (Exception e) { System.err.println("RMI server exception:" + e); e.printStackTrace(); } } }
  • 9. import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.RMISecurityManager; public class RmiClient { // "obj" is the reference of the remote object RmiServerIntf obj = null; public String getMessage() { try { obj = (RmiServerIntf)Naming.lookup("//localhost/RmiServer"); return obj.getMessage(); } catch (Exception e) { System.err.println("RmiClient exception: " + e); return e.getMessage(); } }
  • 10. public static void main(String args[]) { // Create and install a security manager if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } RmiClient cli = new RmiClient(); System.out.println(cli.getMessage()); } }
  • 11. Implementation:  Compile the source code files  javac filename  Create the stub for client and skeleton for server  rmic serverfilename  Start the server  rmiregistry  Ensure security permits are in order  Run the server and client files
  • 12. Common sources of errors  Before running the server, make sure you have an instance of rmiregistry running on the server  Make sure that your CLASSPATH variable is empty  Not having a suitable security policy  Mixing Java versions