Exp2 Sahil
Exp2 Sahil
Theory:
Explain the working and architecture of following with diagram.
Overview: Remote Procedure Call (RPC) is a protocol that enables a program to execute a
procedure (or subroutine) on a different address space (usually on a different physical
machine) as if it were a local procedure call. It abstracts the complexity of network
communication and makes remote calls look like local ones. The process of invoking remote
functions or procedures, handling parameters, and dealing with communication between client
and server is managed by the RPC system.
1.1Architecture of RPC:
In RPC, the procedure call from the client is intercepted by a client stub. This stub packages
the arguments into a message (marshalling) and sends it over the network to the server. The
server then uses a server stub to unpack the message and invoke the procedure. The result is
sent back to the client in a similar manner.
Diagram of RPC Architecture:
Overview:
RPC is a protocol that allows a program to call a procedure or function on a remote server as
if it were a local procedure call. The complexity of network communication is abstracted, so
the developer doesn’t need to manage network connections, message passing, or other
complexities manually.
Working of RPC:
3. Network Communication:
o The marshaled message (with function arguments) is sent over the network to the
remote server.
o RPC uses standard communication protocols like TCP/IP or UDP to transfer data
across the network.
Example:
A client wants to get the balance from a bank server. It calls the getBalance() function, which is
located on the remote server. The client does not know how the server processes the request; it
only knows how to call the function. The server processes the request and sends back the
result, such as balance = 1000.
1. Client Call: The client invokes a local function (stub) as if it were a normal function call.
2. Marshalling: The client stub converts the function parameters into a message format that can
be transmitted over the network.
3. Network Transmission: The marshalled message is sent over the network to the server using
a transport protocol (like TCP or UDP).
4. Server Processing: The server receives the request. The server stub unpacks the message,
extracts the parameters, and calls the corresponding procedure on the server.
5. Execution of the Procedure: The procedure executes on the server side and generates a
result.
6. Return the Result: The server stub packages the result and sends it back to the client via the
network.
7. Unmarshalling and Client Response: The client stub unpacks the result, and the client
application receives the response.
Overview: Remote Method Invocation (RMI) is a Java-specific API that enables objects to
invoke methods on remote objects as if they were local. RMI is based on object-oriented
principles, meaning it works with objects and methods rather than procedures or functions.
Unlike RPC, which works at the function level, RMI operates at the object and method level,
making it more suitable for distributed object-oriented systems. It is primarily used in Java
applications to enable communication between remote objects.
1. Client: The client application, which needs to invoke methods on remote objects.
2. Remote Interface: The interface that defines the methods that can be called remotely. It
extends java.rmi.Remote and declares the methods that can be invoked remotely.
3. Remote Object: A Java object that implements the remote interface and performs the actual
operations.
4. Stub: A proxy object on the client side that represents the remote object. It acts as the
middleman, forwarding method calls to the server.
5. Skeleton: On the server side, the skeleton receives requests from the client, invokes the actual
remote object method, and sends the result back to the client.
6. RMI Registry: A centralized directory service where remote objects are registered so that
clients can locate them.
Overview: Remote Method Invocation (RMI) is a Java-based mechanism that allows one
Java program (a client) to invoke methods on an object located on a different machine (the
server). RMI provides the ability to invoke methods on remote objects as if they were local to
the client. This enables the creation of distributed applications in Java. Unlike traditional
Remote Procedure Calls (RPC), which are function-oriented, RMI is object-oriented and
operates on methods of objects that are accessible remotely.
Before understanding how RMI works, let's first look at the key components involved in an
RMI-based system:
1. Remote Interface: This is the interface that defines the methods that can be invoked
remotely. A remote interface extends java.rmi.Remote and declares the methods that
throw java.rmi.RemoteException.
2. Remote Object: A remote object is an object that implements the remote interface.
This is the object whose methods can be called remotely. It contains the actual
business logic for the methods defined in the remote interface.
3. Stub: The stub is a client-side proxy object that represents the remote object. When
the client calls a method on the stub, it forwards the call to the remote object on the
server. The stub handles the low-level details of remote communication, such as
establishing network connections and serializing the method parameters.
4. Skeleton: The skeleton is the server-side counterpart of the stub. It receives method
calls from the stub, unpacks the parameters, and invokes the actual remote method on
the remote object. The skeleton then sends the result back to the client via the stub.
5. RMI Registry: The RMI registry is a directory service that allows clients to look up
and find remote objects. Remote objects are bound to a name in the registry so that
clients can find them. The registry typically runs on the server machine.
6. RMI Runtime: The RMI runtime manages the communication between the client and
the server. It handles the marshalling and unmarshalling of method parameters,
network communication, and exception handling.
1. Define the Remote Interface: The server defines a remote interface that extends
java.rmi.Remote. This interface contains the method signatures that can be invoked
remotely.
2. Implement the Remote Object: The server creates a class that implements the remote
interface. This class contains the actual logic for the remote method.
3. Export the Remote Object: The remote object is exported so that it can accept
remote method invocations.
4. Bind Remote Object in RMI Registry: The remote object is bound to the RMI
registry using Naming.rebind(). This step allows clients to look up the remote object.
5. Client Lookup: The client looks up the remote object in the RMI registry using
Naming.lookup(), obtaining a reference to the remote object.
6. Method Invocation: The client calls the method on the remote object. The RMI
system uses the stub to forward the method call to the server.
7. Execution on Server: The server executes the method and sends the result back to the
client through the stub and skeleton.
8. Return the Result: The client receives the result as though the method was invoked
locally.
Implementation
Steps:
i. List down the difference between RPC and RMI with example.
Conclusion:
Summary of Experiment
Importance of Experiment
Application of ExperimentJ