Specifications

Remote Procedure Call Programming Guide
This document assumes a working knowledge of network theory. It is intended for programmers who wish
to write network applications using remote procedure calls (explained below), and who want to understand
the RPC mechanisms usually hidden by the rpcgen(1) protocol compiler. rpcgen is described in detail in
the previous chapter, the rpcgen Programming Guide.
Note: Before attempting to write a network application, or to convert an existing non-network application
to run over the network, you may want to understand the material in this chapter. However, for most appli-
cations, you can circumvent the need to cope with the details presented here by using rpcgen. The Generat-
ing XDR Routines section of that chapter contains the complete source for a working RPC service—a
remote directory listing service which uses rpcgen to generate XDR routines as well as client and server
stubs.
What are remote procedure calls? Simply put, they are the high-level communications paradigm used in
the operating system. RPC presumes the existence of low-level networking mechanisms (such as TCP/IP
and UDP/IP), and upon them it implements a logical client to server communications system designed
specifically for the support of network applications. With RPC, the client makes a procedure call to send a
data packet to the server. When the packet arrives, the server calls a dispatch routine, performs whatever
service is requested, sends back the reply, and the procedure call returns to the client.
1. Layers of RPC
The RPC interface can be seen as being divided into three layers.
1
The Highest Layer: The highest layer is totally transparent to the operating system, machine and network
upon which is is run. It’s probably best to think of this level as a way of using RPC, rather than as a part of
RPC proper. Programmers who write RPC routines should (almost) always make this layer available to
others by way of a simple C front end that entirely hides the networking.
To illustrate, at this level a program can simply make a call to rnusers(), a C routine which returns the num-
ber of users on a remote machine. The user is not explicitly aware of using RPC — they simply call a pro-
cedure, just as they would call malloc().
The Middle Layer: The middle layer is really “RPC proper. Here, the user doesn’t need to consider details
about sockets, the UNIX system, or other low-level implementation mechanisms. They simply make
remote procedure calls to routines on other machines. The selling point here is simplicity. It’s this layer
that allows RPC to pass the “hello world” test — simple things should be simple. The middle-layer rou-
tines are used for most applications.
RPC calls are made with the system routines registerrpc() callrpc() and svc_run(). The first two of these
are the most fundamental: registerrpc() obtains a unique system-wide procedure-identification number, and
callrpc() actually executes a remote procedure call. At the middle level, a call to rnusers() is implemented
by way of these two routines.
The middle layer is unfortunately rarely used in serious programming due to its inflexibility (simplicity). It
does not allow timeout specifications or the choice of transport. It allows no UNIX process control or flexi-
bility in case of errors. It doesn’t support multiple kinds of call authentication. The programmer rarely
needs all these kinds of control, but one or two of them is often necessary.
The Lowest Layer: The lowest layer does allow these details to be controlled by the programmer, and for
that reason it is often necessary. Programs written at this level are also most efficient, but this is rarely a
real issue — since RPC clients and servers rarely generate heavy network loads.
Although this document only discusses the interface to C, remote procedure calls can be made from any
language. Even though this document discusses RPC when it is used to communicate between processes
on different machines, it works just as well for communication between different processes on the same
machine.
1
For a complete specification of the routines in the remote procedure call Library, see the rpc(3N) manual
page.
-1-

Summary of content (34 pages)