Experiment Title: Develop a simple Client–Server
Application using RPC or RMI
1. Aim
To design and implement a simple client-server application to demonstrate remote
communication using Remote Procedure Call (RPC) or Remote Method Invocation (RMI).
2. Objectives
● To understand the concept of distributed communication using RPC/RMI.
● To develop client-server architecture for invoking remote methods.
● To analyze communication behavior between local and remote processes.
3. Theory
🔹 What is Remote Communication?
Remote Communication enables a program running on one machine (client) to request
services from a program running on another machine (server).
Distributed systems require mechanisms where:
● Data and resources are shared across a network.
● Processes interact transparently without knowing system-level communication
details.
🔹 Remote Procedure Call (RPC)
RPC allows a function or procedure in one process to be executed in another process,
possibly running on a remote system, without explicitly handling network protocols.
Key Features:
● Client-server architecture
● Transparent invocation (remote call appears local)
● Uses marshalling and stubs
🔹 Remote Method Invocation (RMI)
RMI is Java’s implementation of RPC—used for invoking methods remotely on distributed
Java objects.
Key Components:
Component Description
Remote Interface Declares methods accessible remotely
Server Implements remote methods and registers with RMI
Registry
Client Looks up remote object and invokes methods
🔹 Advantages of RPC/RMI
● Simplifies distributed system communication.
● Supports modular and scalable development.
● Allows seamless interaction between networked components.
Remote Procedure Call (RPC) and Remote Method Invocation (RMI) are communication
mechanisms used in distributed computing that enable processes running on different
machines to interact as if they were executing locally. Both allow applications to be modular,
distributed, scalable, and capable of resource sharing across networks.
1. Remote Procedure Call (RPC)
Definition
RPC is a protocol that allows one program to request a service or execute a function on a
remote system without needing to understand the network communication details.
Key Characteristics of RPC
● Transparency: The remote call appears just like a local function call.
● Language Neutrality: RPC implementations exist for multiple programming
languages (C, Python, Java, etc.).
● Client-Server Model: The client calls a function; the server executes it and returns a
response.
● Platform Independence: RPC may use different architectures, operating systems,
or hardware.
RPC Workflow
1. Client calls a local stub.
2. Stub marshals (encodes) parameters into a message.
3. Message is sent over the network using protocols such as TCP/UDP.
4. Server-side stub receives and unmarshals the message.
5. The required procedure/function runs on the server.
6. The result is marshalled back and returned to the client.
This process gives the illusion of local execution, even though communication occurs over a
network.
Components of RPC
Component Description
Client Initiates the remote call
Server Hosts and executes the requested function
Stub (Client + Server) Acts as proxy to perform marshalling/unmarshalling
RPC Runtime Handles message passing, communication, and error
handling
IDL (Interface Definition Used to define service interfaces in language-neutral
Language) form
Advantages of RPC
● Easy to implement and use due to local invocation abstraction.
● Reduces communication complexity.
● Enables modular distributed system design.
● Supports synchronous and asynchronous communication.
Limitations of RPC
● Network failures may interrupt execution.
● Less suitable for object-oriented environments.
● Can face issues with interoperability and scalability.
● No built-in support for stateful objects.
2. Remote Method Invocation (RMI)
Definition
Remote Method Invocation (RMI) is a Java-based extension of RPC that supports calling
methods on remote Java objects. Unlike RPC, which focuses on procedures or functions,
RMI supports object-oriented distributed computing.
Key Features of RMI
● Object Serialization: Java objects can be sent across the network.
● Pass-by-Reference: Remote objects are accessed as if they are local.
● Dynamic Class Loading: Bytecode for classes can be downloaded dynamically.
● Platform Independent: Built on Java Virtual Machine ecosystems.
RMI Architecture
Component Role
Remote Interface Declares remote methods
Remote Object Implements remote interface
Client Invokes remote methods
Stub & Skeleton (Proxy Layer) Handle marshaling, communication, and invocation
RMI Registry Lookup service for remote objects
Transport Layer Communication protocol (typically TCP/IP)
Note: Latest JVM does not require skeleton files explicitly (generated
dynamically).
RMI Communication Workflow
1. The client requests a remote object reference from the RMI registry.
2. The stub forwards method requests to the remote server.
3. The server executes the method on the actual remote object.
4. The result returns to the client.
Differences Between RPC and RMI
Feature RPC RMI
Paradigm Procedural Object-Oriented
Language Support Multi-language (IDL-based) Java only
Data Primitive data only Objects + primitives
Representation
Transfer Type Serialization limited Full object serialization
Transparency Procedure-level Object and method-level
Use Cases of RPC and RMI
RPC Used In:
● Distributed database systems
● Microservices using gRPC
● Cloud services communication
● Middleware systems like CORBA and SunRPC
RMI Used In:
● Distributed Java applications
● Enterprise systems (e.g., J2EE, EJB)
● Remote sensor monitoring and control
● Research and learning platforms
Modern Extensions of RPC/RMI
● gRPC — Lightweight, fast, Google-developed RPC using Protocol Buffers.
● JSON-RPC / XML-RPC — Web-based standards for cross-platform remote
invocation.
● Web Services (SOAP, REST) — Modern alternatives for distributed communication.
RPC and RMI are foundational communication techniques in distributed systems. While
RPC provides function-level communication across multiple platforms, RMI extends these
concepts to object-oriented environments, enabling seamless Java-based distributed
software development. Together, they form the basis for efficient, scalable, and modular
distributed architectures.
4. Hardware and Software Requirements
Componen Specification
t
OS Windows/Linux
Language Java (for RMI) or Python/C RPC Framework
Tools Java JDK 8+ , Terminal / Command Prompt
5. Program Implementation (Java RMI Example)
5.1 Remote Interface ([Link])
import [Link];
import [Link];
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
5.2 Server Implementation ([Link])
import [Link];
import [Link];
import [Link];
public class HelloServer implements Hello {
public String sayHello() {
return "Hello from Remote Server!";
}
public static void main(String[] args) {
try {
HelloServer obj = new HelloServer();
Hello stub = (Hello) [Link](obj, 0);
Registry registry = [Link](1099);
[Link]("Hello", stub);
[Link]("Server ready...");
} catch (Exception e) {
[Link]("Server exception: " + [Link]());
}
}
}
5.3 Client Program ([Link])
import [Link];
import [Link];
public class HelloClient {
public static void main(String[] args) {
try {
Registry registry = [Link]("localhost");
Hello stub = (Hello) [Link]("Hello");
String response = [Link]();
[Link]("Response from Server: " + response);
} catch (Exception e) {
[Link]("Client exception: " + [Link]());
}
}
}
6. Execution Steps
1. Compile all files:
javac *.java
2. Start RMI Registry:
rmiregistry
3. Run server:
java HelloServer
4. Run client:
java HelloClient
7. Sample Expected Output
On Server:
Server ready...
On Client:
Response from Server: Hello from Remote Server!
8. Result
The remote client successfully invoked the method on the server using RMI, demonstrating
remote communication.
9. Questions of Curiosity:
1. What is RPC/RMI?
2. What is Marshalling?
3. What is a stub in RMI?
4. What is the role of the RMI registry?
5. Modify the application to send two numbers and return their sum using RMI.
6. Implement authentication in RMI communication.
7. Compare performance between RPC and RMI.