What is remote method invocation in java?
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.
Working of RMI
The communication between client and server is handled by using two intermediate objects: Stub object (on client side) and Skeleton object (on server side).
The stub object on the client machine builds an information block and sends this information to the server.
The block consists of
1)An identifier of the remote object to be used
2)Method name which is to be invoked
3)Parameters to the remote JVM
The skeleton object passes the request from the stub object to the remote object. It performs following tasks
1) It calls the desired method on the real object present on the server.
2) It forwards the parameters received from the stub object to the method.
Steps to implement Interface
- Defining a remote interface
- Implementing the remote interface
- Creating Stub and Skeleton objects from the implementation class using rmic (rmi complier)
- Start the rmiregistry
- Create and execute the server application program
- Create and execute the client application program.