Remote Procedure Call

Ordinary procedure call

The imperative languages use the procedure as a means of structuring the language. The language will have conditionals, loops and procedure calls.

When a procedure is called, it usually makes use of the stack, pushing parameters onto the stack and reserving space for local variables:

Parameter types

Value parameters

When a parameter is called by value, the actual value of the parameter is placed on the stack. This can then be used and modified by the procedure without any change to any original variable.

Reference parameters

The address of the parameter is passed into the procedure. Any use of the parameter within the procedure uses the address to access/change the value.


Languages such as Ada use in and out parameters. An in parameter is copied on procedure entry. An out parameter is restored on procedure exit.

C does not have call by reference, but only call by value. The value may be an address which can be dereferenced to change the value at that address. Most other procedural languages have both call by reference and by value.

Remote procedure call

The socket method of network use is a message-based system, in which one process writes a message to another. This is a long way from the procedural model, or the method call of O/O.

The remote procedure call is intended to act like a procedure call, but to act across the network transparently.

The process makes a remote procedure call by pushing its parameters and a return address onto the stack, and jumping to the start of the procedure. The procedure itself is responsible for accessing and using the network.

After the remote execution is over, the procedure jumps back to the return address. The calling process then continues.

What should RPC look like?

The network needs to be made invisible, so that everything looks just like ordinary procedure calls. The calling process would execute a C procedure call such as
remote_time(machine, &time_buf);
All networking should be done by the RPC implementation, such as connecting to the remote machine. On the remote machine a corresponding C function gets executed:
int remote_time(char *time_buf)
{ struct tm *time;
  time_t t;

  time = localtime(&t);
  return 0;


When the calling process calls a procedure, the action performed by that procedure will not be the actual code as written, but code that begins network communication. It has to connect to the remote machine, send all the parameters down to it, wait for replies, do the right thing to the stack and return. This is the client side stub.

The server side stub has to wait for messages asking for a procedure to run. It has to read the parameters, and present them in a suitable form to execute the procedure locally. After execution,it has to send the results back to the calling process.

  1. The client calls the local stub procedure. The stub packages up the parameters into a network message. This is called marshalling.
  2. Networking functions in the O/S kernel are called by the stub to send the message.
  3. The kernel sends the message(s) to the remote system. This may be connection-oriented or connectionless.
  4. A server stub unmarshals the arguments from the network message.
  5. The server stub executes a local procedure call.
  6. The procedure completes, returning execution to the server stub.
  7. The server stub marshals the return values into a network message.
  8. The return messages are sent back.
  9. The client stub reads the messages using the network functions.
  10. The message is unmarshalled. and the return values are set on the stack for the local process.

Relation to HOPP

RPC is a procedural example of HOPP (Half Object plus Protocol). Client procedures are like the methods of a client HOPP. The client-side implementation establishes a socket connection, sends parameters and reads results. The server procedures are like the methods of the server HOPP. The server-side implementation is called by a server and contains the real implementation of the procedure.

Components of RPC

(Think what would be involved in automating generation of a HOPP pair for your assignment. RPC does this automated generation.)

An RPC system consists of the following pieces

The Sun RPC uses a standard format called XDR. The ordering is big-endian and the minimum size of any field is 32 bits. DCE uses a different format, as does Xerox Courier.


An ordinary procedure may cause an error by executing an illegal instruction such as divide by zero or illegal memory reference.

What errors can occur in a remote procedure call?

Can't find the server

If the server is not there, an error indication should be returned.

In C, it may be possible to return an error value for some functions, but not for all. Anyway, in Ada, if you have to use a function then you can't use the parameters like you can with procedures.

In Ada you can raise an exception, or in C generate a signal. However, Pascal has neither of these concepts.

There is no language-independant solution.

Request to server is lost

This is easy: the client stub sets a timer that expires if no reply is received. Send the message again.

Unfortunately, what if the server has in fact received the message, but is just being slow. The request may end up being executed twice or more. This can be avoided by including an identifier in the message to stop it being retried if it has already been received.

Reply from server is lost

This is the same type of problem.

Server crashes

In this case, when the server comes back up, it will probably have no record of having received the message, and will probably do it again. This can be okay. If the message was a funds transfer message then it probably won't be.

Preventing this is the at most once problem.

One solution is to not resend messages. In this case you hit the at least once problem.

Client crashes

This can be guarded against be keeping a record on disk of each RPC message sent. This slows things down a bit though.


Sun RPC is also known as ONC (Open Network Connection). This is a common RPC mechanism, available on lots of platforms. It was originally designed for C as client and server. There are several Java implementations ( is open source), so a Java client can make ONC calls to a C server and vice versa.

ONC consists of


Valid data types supported by XDR include Things like variable length arrays get represented in C by a structure with first field the length, second field the data.

RPC specification

A file with a ``.x'' suffix acts as a remote procedure specification file. It defines functions that will be remotely executed functions. Functions are restricted: they may take at most one in parameter, and return at most one out parameter as the function result.

If you want to use more than one in parameter, you have to wrap them up in a single structure, and similarly with the out values.

Multiple functions may be defined at once. They are numbered from one upwards, and any of these may be remotely executed.

The specification defines a program that will run remotely, made up of the functions. The program has a name, a version number and a unique identifying number (chosen by you).

For example, a program may have two local functions to find the date on a machine. The local definitions could be (in C)

long bin_date(void);
char *str_date(long);
or in Java
long bin_date();
String str_date(long);
The program with these specified as remote procedures for a remote machine would define the two functions bin_date and str_date in file rdate.x:
program RDATE_PROG {
  version RDATE_VERS {
    long   BIN_DATE(void) = 1;
    string STR_DATE(long) = 2;
  } = 1;
} = 1234567;
Each of these functions could have one argument.


This is available from jrpcgen is a program that takes a specification file as command line parameter and generates Java source files that can be used as client and server stubs. Usage

java -jar jrpcgen.jar rdate.x

This generates Java files and These act as the client and server HOPP's. The client contains methods

public class rdateClient extends OncRpcClientStub {

    public rdateClient(InetAddress host, int protocol)
           throws OncRpcException, IOException;
    public int BIN_DATE_1()
           throws OncRpcException, IOException;
    public String STR_DATE_1(int arg1)
           throws OncRpcException, IOException;
// End of
The client makes ordinary method calls BIN_DATE_1 and STR_DATE_1 on the client stub.

The server stub contains methods

public abstract class rdateServerStub extends OncRpcServerStub implements OncRpcDispatchable {

    public rdateServerStub();

    public void dispatchOncRpcCall(OncRpcCallInformation call, int program, int version, int procedure)
           throws OncRpcException, IOException;

    public abstract int BIN_DATE_1();
    public abstract String STR_DATE_1(int arg1);
// End of
The server stub needs to be subclassed to implement BIN_DATE_1 and STR_DATE_1


DCOM is the Microsoft equivalent of ONC. It is based on DCE RPC from the OSF (DCE = Distributed Computing Environment, OSF = Open Software Foundation). There is a commercial implementation of Java classes talking DCOM, but this costs US$5,000 per license. This is written in pure Java, and will run on any platform. Sun are in the process of developing their own classes, but these will only run on Windows, and also seem to require IIOP (the transport protocol for CORBA).

It is maintained by Jan Newmarch.
Last modified: 11 May, 1996
Copyright © Jan Newmarch, Monash University, 2007
Creative Commons License This work is licensed under a Creative Commons License
The moral right of Jan Newmarch to be identified as the author of this page has been asserted.