Remote Method Invocation(RMI) with java
RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing in one system (JVM) to access/invoke an object running on another JVM.
RMI is used to build distributed applications; it provides remote communication between Java programs. It is provided in the package java.rmi.
Architecture of an RMI Application:
- ransport Layer − This layer connects the client and the server. It manages the existing connection and also sets up new connections.
- Stub − A stub is a representation (proxy) of the remote object at client. It resides in the client system; it acts as a gateway for the client program.
- Skeleton − This is the object which resides on the server side. stub communicates with this skeleton to pass request to the remote object.
- RRL(Remote Reference Layer) − It is the layer which manages the references made by the client to the remote object.
Different between RPC and RMI
The common difference between RPC and RMI is that RPC only supports procedural programming whereas RMI supports object-oriented programming. Another major difference between the two is that the parameters passed to remote procedures call consist of ordinary data structures.
Simple RMI application example:
01. HelloService.java(Interface)
02. HelloServant.java
03. ApplicationServer.java
04. Client.java
HelloService.java
HelloServant.java
ApplicationServer.java
Client.java
Output: