Remote Method Invocation(RMI) with java

Prarthanawickramarathne1
2 min readJul 17, 2020

--

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:

Figure1:Architecture
  • 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.

Figure2:Difference between RPC and RMI

Simple RMI application example:

01. HelloService.java(Interface)

02. HelloServant.java

03. ApplicationServer.java

04. Client.java

HelloService.java

Figure3:HelloService.java

HelloServant.java

Figure4:HelloServant.java

ApplicationServer.java

Figure5:ApplicationServer.java

Client.java

Figure6:Client.java

Output:

Figure7:Output

--

--

Prarthanawickramarathne1
Prarthanawickramarathne1

Written by Prarthanawickramarathne1

Undergratuate Software Engineering Student in university of Kelaniya

No responses yet