Remote Procedure Call (RPC)

Keshara Piyumal
3 min readJul 15, 2020

--

R emote Procedure Call (RPC) is a protocol that one program can use to request a service from a program located in another computer on a network without having to understand the network’s details. RPC is used to call other processes on the remote systems like a local system. A procedure call is also sometimes known as a function call or a subroutine call.

A client has a request message that the RPC translates and sends to the server. This request may be a procedure or a function call to a remote server. When the server receives the request, it sends the required response back to the client. The client is blocked while the server is processing the call and only resumed execution after the server is finished.

Client-Server Communication

Here I am going to explain more about RPC, using JAX-RPC which was an API for building Web services and clients that used remote procedure calls (RPC) and XML. In JAX-RPC, a remote procedure call is represented by an XML-based protocol such as SOAP (SOAP RPC Style). These calls and responses are transmitted as SOAP messages over HTTP.

To demonstrate Java-RPC, I have implemented a simple application to check a person is an adult or a teenager by using the age as a param.

Web Service Implementation

AgeChecker.java

Server side interface : AgeChecker.java

This is the same interface which is used in client-side as well. The abstract method of the interface, which is checkAge is defined as a web method.

AgeCheckerImpl.java

Implementation of abstract method : AgeCheckerImpl.java

ServiceAsPublisher.java

Web Service : ServiceAsPublisher.java

When we run the above web service, ServiceAsPublisher.java it outputs as below & server is starting at the port 7788 and also ready to reply for the client requests.

Client Side Implementation

AgeChecker.java

Client side interface : AgeChecker.java

AgeCheckerClient.java

Here the client also using same interface which was used in web service and when run the above AgeCheckerClient.java it outputs as below.

That means it could be able to request a service from a program located in another computer on a network without having to understand the network’s details using RPC. That’s how the JAX-RPC works. I have shared the github link of the above code repository below. See you again with another interesting article. Thank you!

This is the GitHub link of the repository of above code. https://github.com/KesharaPiyumal/Java-RPC

--

--

Keshara Piyumal
Keshara Piyumal

Written by Keshara Piyumal

Senior Software Engineer | B.Sc. Honors in Software Engineering | University of Kelaniya, Sri Lanka

No responses yet