E
ebby83
Hi I am trying to run this basic Timestamp service using RPC . Here are
the file for the same .
I run it the foll way:
gdoshi@hobbes:!:rpcgen date.x
gdoshi@hobbes:!:lsdate.h date_clnt.c dateproc.cdate.x
date_svc.c rdate.c
gdoshi@hobbes:!:cc -o rdate rdate.c date_clnt.c
gdoshi@hobbes:!:cc -o dateproc dateproc.c date_svc.c
gdoshi@hobbes:!:./dateproc&
[1] 1611
gdoshi@hobbes:!: rdate hobbes.seas.gwu.edu
rdate: connect: Connection refused
[1]+ Done ./dateproc
I always get a connection refused whenever I do this. I also tried this
with localhost. PLS HELP!!! ..
dateproc.c
#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);
}
rdate.c
#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);
}
date.h
#ifndef _DATE_H_RPCGEN
#define _DATE_H_RPCGEN
#include <rpc/rpc.h>
#define DATE_PROG 0x31234567
#define DATE_VERS 1
#define BIN_DATE 1
extern long * bin_date_1();
#define STR_DATE 2
extern char ** str_date_1();
extern int date_prog_1_freeresult();
#endif /* !_DATE_H_RPCGEN */
the file for the same .
I run it the foll way:
gdoshi@hobbes:!:rpcgen date.x
gdoshi@hobbes:!:lsdate.h date_clnt.c dateproc.cdate.x
date_svc.c rdate.c
gdoshi@hobbes:!:cc -o rdate rdate.c date_clnt.c
gdoshi@hobbes:!:cc -o dateproc dateproc.c date_svc.c
gdoshi@hobbes:!:./dateproc&
[1] 1611
gdoshi@hobbes:!: rdate hobbes.seas.gwu.edu
rdate: connect: Connection refused
[1]+ Done ./dateproc
I always get a connection refused whenever I do this. I also tried this
with localhost. PLS HELP!!! ..
dateproc.c
#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);
}
rdate.c
#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);
}
date.h
#ifndef _DATE_H_RPCGEN
#define _DATE_H_RPCGEN
#include <rpc/rpc.h>
#define DATE_PROG 0x31234567
#define DATE_VERS 1
#define BIN_DATE 1
extern long * bin_date_1();
#define STR_DATE 2
extern char ** str_date_1();
extern int date_prog_1_freeresult();
#endif /* !_DATE_H_RPCGEN */