|
Home > Archive > Unix Programming > March 2005 > RPC Blues (arrrghh) H-E-L-P
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
RPC Blues (arrrghh) H-E-L-P
|
|
| 50295@web.de 2005-03-17, 5:55 pm |
| I'm trying to compile the RPC example on this webpage:
http://www.cs.wpi.edu/~cs4513/b01/w...ek4-sunrpc.html
--------------------------------------------------------------
Client:
/*
* rdate.c client program for remote date program
*/
#include <stdio.h>
#include <rpc/rpc.h> /* standard RPC include file */
#include "date.h" /* this file is generated by rpcgen */
main(int argc, char *argv[])
{
CLIENT *cl; /* RPC handle */
char *server;
long *lresult; /* return value from bin_date_1() */
char **sresult; /* return value from str_date_1() */
if (argc != 2) {
fprintf(stderr, "usage: %s hostname\n", argv[0]);
exit(1);
}
server = argv[1];
/*
* Create client handle
*/
if ((cl = clnt_create(server, DATE_PROG, DATE_VERS, "udp")) ==
NULL) {
/*
* can't establish connection with server
*/
clnt_pcreateerror(server);
exit(2);
}
/*
* First call the remote procedure "bin_date".
*/
if ( (lresult = bin_date_1(NULL, cl)) == NULL) {
clnt_perror(cl, server);
exit(3);
}
printf("time on host %s = %ld\n",server, *lresult);
/*
* Now call the remote procedure str_date
*/
if ( (sresult = str_date_1(lresult, cl)) == NULL) {
clnt_perror(cl, server);
exit(4);
}
printf("time on host %s = %s", server, *sresult);
clnt_destroy(cl); /* done with the handle */
exit(0);
}
--------------------------------------------------------------
Remote procedures:
/*
* dateproc.c remote procedures; called by server stub
*/
#include <rpc/rpc.h> /* standard RPC include file */
#include "date.h" /* this file is generated by rpcgen */
/*
* Return the binary date and time
*/
long *bin_date_1()
{
static long timeval; /* must be static */
timeval = time((long *) 0);
return &timeval;
}
/*
* Convert a binary time and return a human readable string
*/
char **str_date_1(long *bintime)
{
static char *ptr; /* must be static */
ptr = ctime(bintime); /* convert to local time */
return &ptr;
}
--------------------------------------------------------------
/*
* date.x Specification of the remote date and time server
*/
/*
* Define two procedures
* bin_date_1() returns the binary date and time (no arguments)
* str_date_1() takes a binary time and returns a string
*
*/
program DATE_PROG {
version DATE_VERS {
long BIN_DATE(void) = 1; /* procedure number = 1 */
string STR_DATE(long) = 2; /* procedure number = 2 */
} = 1; /* version number = 1 */
} = 0x31234567; /* program number = 0x31234567 */
--------------------------------------------------------------
and all is well till I try:
cc -o dateproc dateproc.c date_svc.c
the result:
dateproc.c: In function `bin_date_1':
dateproc.c:13: number of arguments doesn't match prototype
date.h:22: prototype declaration
dateproc.c: At top level:
dateproc.c:25: conflicting types for `str_date_1'
date.h:25: previous declaration of `str_date_1'
dateproc.c: In function `str_date_1':
dateproc.c:27: warning: assignment makes pointer from integer without a
cast
What's going wrong???????
Thanks,
- Olumide
| |
|
|
| 50295@web.de 2005-03-17, 8:48 pm |
| Eureka! I solved it.
For posteriry's sake I'm answering my own questions.
First to compile the remote procedure interface/specification file
foo.x (with rpcgen), in order to get a:
(1) client stub source file (foo_clnt.c),
(2) server stub source file (foo_svc.c),
(3) machine-independent eXternal Data Representation filter (foo_xdr.c)
if necessary (depends on if you've defined a struct in foo.x), and ...
(4) a header file (foo.h) - to be used by the client and server source
files and stubs
The key however is to make sure that you implement the necessary
interfaces defined specifed in foo.h.
Accordingly, the remote procedure file dateproc.c shold look like::
#include <stdio.h>
#include <time.h>
#include <rpc/rpc.h>
#include "date.h"
long bin_date(void)
{
return (long) time(NULL);
}
char *str_date(long t)
{
return ctime((time_t *) &t);
}
long *bin_date_1(void *p, CLIENT *cl)
{
static long t;
t = bin_date();
return &t;
}
long * bin_date_1_svc(void *p, struct svc_req *cl){
CLIENT *client;
return(bin_date_1(NULL, client));
}
char **str_date_1(long *p, CLIENT *cl)
{
static char *s;
s = str_date(t);
return &s;
}
char **str_date_1_svc(long *p, struct svc_req *cl){
CLIENT *client;
return(str_date_1(NULL, client));
}
- Olumide
|
|
|
|
|