next up previous
Next: Transparent RPC Up: Communication across a Previous: OS Interface: Sockets

Sun RPC

Both UDP and TCP require a client to encode its request and parameters in the data area of the message, and then wait for a reply on the reply port of the message. The server in turn needs to decode the request, perform the service, and then encode the reply. It would be more useful if the client could directly call a remote procedure which the server executes to service the request.

Sun RPC demonstrates how a remote procedure call paradigm can be supported on top of UDP or TCP via library routines. Each server registers a procedure pair via the registerrpc call,

registerrpc (prognum, versnum, procnum, procaddr, inproc, outproc)
A client can then invoke callrpc to call the remote procedure:
callrpc (host, prognum, versum, procnum, arg, inproc, outproc)
The procedure callrpc takes as arguments the machine number of the server, the procedure identifier, and the input and output parameters. It sends an appropriate UDP or TCP message to the destination machine, waits for a reply, extracts the results, and returns them in the output parameters.

The XDR (eXternal Data Routines) are responsible for marshalling/unmarshalling procedure parameters onto/from XDR streams. Example of XDR (input & output) procedure :

typedef struct {
    int f1;
    float f2 } S;

xdr\_s (xdrsp, arg)
    XDRS *xdrsp;
	S *arg;
{
	xdr\_int (xdrsp, \&arg->f1);
	xdr\_float (xdrsp, \&arg->f2);
}
It is called in the marshalling/unmarshalling modes by the client and server RPC system. In the marshalling mode, it writes the argument onto the stream and in the unmarshalling mode it extracts data from the stream into the argument.

Prasun Dewan
Tue Sep 24 14:33:02 EDT 1996