SlideShare une entreprise Scribd logo
1  sur  13
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

Contenu connexe

Tendances

Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)Nilesh Valva
 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Sonali Parab
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocationDew Shishir
 
Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVAPrankit Mishra
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method InvocationPaul Pajo
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocationashishspace
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMIbackdoor
 
Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI PresentationMasud Rahman
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Peter R. Egli
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with codekamal kotecha
 

Tendances (19)

Introduction To Rmi
Introduction To RmiIntroduction To Rmi
Introduction To Rmi
 
Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)
 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)
 
Rmi
RmiRmi
Rmi
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 
Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVA
 
Java RMI
Java RMIJava RMI
Java RMI
 
Rmi ppt
Rmi pptRmi ppt
Rmi ppt
 
Rmi presentation
Rmi presentationRmi presentation
Rmi presentation
 
Rmi ppt-2003
Rmi ppt-2003Rmi ppt-2003
Rmi ppt-2003
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
 
Rmi architecture
Rmi architectureRmi architecture
Rmi architecture
 
Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI Presentation
 
Java rmi tutorial
Java rmi tutorialJava rmi tutorial
Java rmi tutorial
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 
Java RMI
Java RMIJava RMI
Java RMI
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 

Similaire à Java remote method invocation

Similaire à Java remote method invocation (20)

Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
 
Java RMI
Java RMIJava RMI
Java RMI
 
Call Back
Call BackCall Back
Call Back
 
Module 1 Introduction
Module 1   IntroductionModule 1   Introduction
Module 1 Introduction
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 
Rmi
RmiRmi
Rmi
 
17rmi
17rmi17rmi
17rmi
 
ADB Lab Manual.docx
ADB Lab Manual.docxADB Lab Manual.docx
ADB Lab Manual.docx
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
Run rmi
Run rmiRun rmi
Run rmi
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
JavaExamples
JavaExamplesJavaExamples
JavaExamples
 
Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMI
 
Rmi
RmiRmi
Rmi
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Rmi3
Rmi3Rmi3
Rmi3
 
Rmi
RmiRmi
Rmi
 
Remote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programmingRemote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programming
 

Dernier

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Dernier (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).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