The first way invented to allow at computer client to call a remote method present on the computer server was RMI, after was created the middleware CORBA and now the most used way to make the communication between client and server is web services.
A middleware is another layer of iso-osi that is over the fourth layer (transport) and has this two functions:
- hides how client and server exchange data because client sends message to local proxy called stub, this stub sends message to proxy on server called skeleton and skeleton sends message to remote app on computer server.
- Allows to communicate different and heterogeneous architecture, software because uses a IDL (interface definition language) for making an interface, for this reason, the implementation is independent from the language used
The first type of middleware was CORBA (common request object architecture), it is made of Remote procedure call but now the most used middleware to exchange data between hosts is web services.
In this article I want to explain what is Remote Method Invocation, so it is a call of remote procedure (Remote procedure call RPC used on java).
All methods published on server are registered on RMI Registry (like UDDI for web services). I have written below the steps to perform the RMI call.
- client calls the local method (stub) to perform this operation
- the stub on computer client calls RMI Registry to know whether that method exists and the correct way to call it
- client stub calls this method on server
- server skeleton receives this request and communicate with the software on server, when it receives the response, sends this response to the client stub.
I made a simple software called RMI Echo that allows the client to send a string on server and server returns the same string to the client.
This software was made of the classic J2EE technology without graphical interface because this is the first software without GUI (it is one my target) and also because it is easy to use: it is enough to run these two java files:
- First of all it is necessary to run RMI registry by typing a command rmiregistry
- The second step is to run server
- The third step is to run client with two parameters: IP and string to pass to server (the second element of the socket, the address of TCP so the port number is fixed=25725 to simplify the operations)
- The string is sent to the server and this server sends this string on the client.
when you use RMI in java web application classic it is not necessary to run RMIRegistry
this resource is available here