CITS3002 Computer Networks  
prev
next CITS3002 help3002 CITS3002 schedule  

RPC Server-side Code in C

//  date_server.c - remote procedures; called by server stub

#include  <time.h>
#include  <rpc/rpc.h>           // standard RPC include file
#include  "date.h"              // this file is generated by rpcgen

//  RETURN THE DATE AND TIME AS AN INTEGER
long *bin_date_1_svc(void *unused1, struct svc_req *unused2)
{
    static long timeval;        // must be declared as a static

    timeval = time(NULL);

    return (&timeval);
}

//  RECEIVE AN INTEGER TIME VALUE AND RETURN A HUMAN READABLE STRING
char **str_date_1_svc(long *bintime, struct svc_req *unused)
{
    static char *ptr;           // must be declared as a static

    ptr = ctime(bintime);       // convert to local time

    return (&ptr);              // return the address of pointer
}




CITS3002 Computer Networks, Lecture 10, Architecture independent applications, p9, 8th May 2024.