4.4 Rmi RPC
4.4 Rmi RPC
4.4 Rmi RPC
5. The server stub unpacks the parameters and calls the server.
6. The server does the work and returns the result to the server stub.
7. The server stub packs it in a message and calls its local OS.
8. The server's OS sends the message to the client's OS.
9. The client's OS gives the message to the client stub.
10. The client stub unpacks the result and returns to the client.
RPC Vs RMI
With RPC you can just call remote functions exported into
a server,
RMI you can have references to remote objects and
invoke their methods, and also pass and return more
remote object references that can be distributed among
many JVM instances, so it's much more powerful.
Remote method invocation(RMI)
• Remote Method Invocation (RMI) is an API which allows an object to
invoke a method on an object that exists in another address space,
which could be on the same machine or on a remote machine.
• Through RMI, object running in a JVM present on a computer (Client
side) can invoke methods on an object present in another JVM (Server
side).
• RMI creates a public remote server object that enables client and
server side communications through simple method calls on the
server object.
• RMI is used for building distributed application.
Working of RMI
Marshalling
During communication between two machines
through RPC or RMI, parameters are packed
into a message and then sent over the
network.
The skeleton is a class, acts as a gateway for the server side object.
All the incoming requests are routed through it.
When the skeleton receives the incoming request, it does the following
tasks:
• It reads the parameter for the remote method
• It invokes the method on the actual remote object, and
• It writes and transmits (marshals) the result to the caller.
RMI Application Development
Steps for Developing the RMI Application
• Define the remote interface
• Define the class and implement the
remote interface(methods) in this class
• Define the Server side class
• Define the Client side class
• Compile the all four source(java) files
• Generate the Stub/Skeleton class by
command
• Start the RMI remote Registry
• Run the Server side class
• Run the Client side class(at another JVM)