Remote Procedure Calls
The task is to implement the Time server using RPCs. It has two procedures bin_time , that returns the current time as a long int, and str_time, that convert the time from long int to string.
Compile the following XDR description of the procedures:
program TIME_PROG {
version TIME_VERS {
long BIN_TIME(void) = 1; /* Procedure number 1 */
string STR_TIME(long) = 2; /* Procedure number 2 */
} = 1; /* Version number 1 */
} = 0x31234567; /* Program number 0x31234567 */
Use rpcgen to generate the stub files, sample files and Makefile:
rpcgen -a -C time.xdr
Add to the sample files the code to implement the application:
To the server file:
long * bin_time_1_svc(void *argp, struct svc_req *rqstp)
{
static long result;
result= time((time_t *) 0);
return (&result);
}
char ** str_time_1_svc(long *argp, struct svc_req *rqstp)
{
static char * result;
static tstr[128];
long t, hour, min, sec;
t= *argp;
sec= t % 60; t /= 60;
min= t % 60; t /= 60;
hour= t % 24;
sprintf(tstr, "hora %u:%u:%u", hour, min, sec);
result= tstr;
return (&result);
} To the client file:
void time_prog_1(char *host)
{
...
result_1 = bin_date_1((void *)&bin_date_1_arg, clnt);
if (result_1 == (long *) NULL)
clnt_perror(clnt, "call failed");
result_2 = str_date_1((long *) result_1, clnt);
if (result_2 == (char **) NULL)
clnt_perror(clnt, "call failed");
printf("Time: %u %s\n", *result_1, *result_2);
}
... Compile and run the application:
make makefile.time
Make a clear description of the way this program works.
What are the advantages and disadvantages of using RPCs over sockets?
Rewrite the calculator program you wrote for the last laboratory assignment substituting the datagrams sockets for RPCs.