When a procedure is called, it usually makes use of the stack,
pushing parameters
onto the stack and reserving space for local variables:
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.
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.
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(&t);
time = localtime(&t);
strcpy(time_buf,
asctime(time));
return 0;
}
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.
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.
(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.
What errors can occur in a remote procedure call?
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.
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.
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.
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 ( http://remotetea.sourceforge.net is open source), so a Java client can make ONC calls to a C server and vice versa.
ONC consists of
rpcgen
to generate C client and server
stubs
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)
or in Java
long bin_date(void);
char *str_date(long);
The program with these specified as
remote procedures for a remote
machine would define the two functions
long bin_date();
String str_date(long);
bin_date
and
str_date
in file rdate.x
:
Each of these functions could have one argument.
program RDATE_PROG {
version RDATE_VERS {
long BIN_DATE(void) = 1;
string STR_DATE(long) = 2;
} = 1;
} = 1234567;
This is available from
http://remotetea.sourceforge.net/
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 rdateClient.java
and rdateServerStub.java
. These act as the
client and server HOPP's. The client contains methods
The client makes ordinary method calls
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 rdateClient.java
BIN_DATE_1
and STR_DATE_1
on the client stub.
The server stub contains methods
The server stub needs to be subclassed to implement
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 rdateServerStub.java
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).