Beruflich Dokumente
Kultur Dokumente
Introduction
Four sample programs are provided as part of the RPC library. They are paired into two sets with
each set having a client and server program. The client of the first pair, using the RPC library, simply
sends a user selected message to the server, which then prints the message to stderr.
The client of the second pair sends a user selected group of arguments to the server via RPC. The
server then sorts the arguments and returns the results to the client, which then prints the sorted result
to stderr.
The programs can be built using the sample JCL provided to build any RPC library program. Once
built, the server program should be started and then the corresponding client should be started.
Then execute the client, msgcln, by calling it from TSO or batch with the name of the host on which
the server is running and then a message. (Use the appropriate C compiler parameter passing
conventions.)
CALL 'MYLOAD(MSGCLNT)' 'SERVERHOST HELLO'
Sample Programs
This section includes the source code listings for the sample programs.
MSGSVC
This is the source code listing for the msgsvc program:
#include <stdio.h>
#include <rpc.h>
#include <pmapclnt.h>
#include <msg.h>
main()
{
SVCXPRT *transp;
(void)pmap_unset(MESSAGEPROG, MESSAGEVERS);
transp = svcudp_create(RPC_ANYSOCK);
if (transp == (SVCXPRT *)NULL)
{
(void)fprintf(stderr, "CANNOT CREATE UDP SERVICE.\n");
exit(16);
}
if (!svc_register(transp, MESSAGEPROG, MESSAGEVERS, messageprog_1, IPPROTO_UDP))
{
(void)fprintf(stderr,
"UNABLE TO REGISTER (MESSAGEPROG, MESSAGEVERS, UDP).\n");
exit(16);
}
switch (rqstp->rq_proc)
{
case NULLPROC:
(void)svc_sendreply(transp, xdr_void, (char *)NULL);
return;
case PRINTMESSAGE:
xdr_argument = xdr_wrapstring;
xdr_result = xdr_int;
local = (char *(*)()) printmessage_1;
break;
default:
svcerr_noproc(transp);
return;
}
bzero((char *)&argument, sizeof(argument));
if (!svc_getargs(transp, xdr_argument, &argument))
{
svcerr_decode(transp);
return;
}
result = (*local)(&argument, rqstp);
if (result != (char *)NULL &&
!svc_sendreply(transp, xdr_result, result))
{
svcerr_systemerr(transp);
}
if (!svc_freeargs(transp, xdr_argument, &argument))
{
(void)fprintf(stderr, "UNABLE TO FREE ARGUMENTS\n");
exit(16);
}
return;
}
char *printmessage_1(msg)
char **msg;
{
static char result;
MSGCLNT
This is the source listing for the msgclnt program:
/* @(#)rprintmsg.c 2.1 88/08/11 4.0 RPCSRC */
#include <stdio.h>
#include <rpc.h>
#include <time.h>
#include <msg.h>
main(argc, argv)
int argc;
char *argv[];
{
CLIENT *cl;
int *result;
char *server ;
char *message;
if (argc < 3)
{
fprintf(stderr, "USAGE: %s HOST MESSAGE\n", argv[0]);
exit(16);
}
server = argv[1];
message = argv[2];
if (*result == 0)
{
fprintf(stderr, "%s: SORRY, %s COULDN'T PRINT YOUR MESSAGE\n",
argv[0], server );
exit(16);
}
SORTSVC
This is the source code listing for the sortsvc program:
#include <stdio.h>
#include <rpc.h>
#include <pmapclnt.h>
#include <sort.h>
main()
{
SVCXPRT *transp;
(void)pmap_unset(SORTPROG, SORTVERS);
transp = svcudp_create(RPC_ANYSOCK);
if (transp == (SVCXPRT *)NULL)
{
(void)fprintf(stderr, "CANNOT CREATE UDP SERVICE.\n");
exit(16);
}
if (!svc_register(transp, SORTPROG, SORTVERS, sortprog_1, IPPROTO_UDP))
{
(void)fprintf(stderr,
"UNABLE TO REGISTER (SORTPROG, SORTVERS, UDP).\n");
exit(16);
}
svc_run();
(void)fprintf(stderr, "SVC_RUN RETURNED\n");
exit(16);
return(0);
}
char *result;
bool_t (*xdr_argument)();
bool_t (*xdr_result)();
char *(*local)();
switch (rqstp->rq_proc)
{
case NULLPROC:
(void)svc_sendreply(transp, xdr_void, (char *)NULL);
return;
case SORT:
xdr_argument = xdr_sortstrings;
xdr_result = xdr_sortstrings;
local = (char *(*)()) sort_1;
break;
default:
svcerr_noproc(transp);
return;
}
bzero((char *)&argument, sizeof(argument));
if (!svc_getargs(transp, xdr_argument, &argument))
{
svcerr_decode(transp);
return;
}
result = (*local)(&argument, rqstp);
if (result != (char *)NULL &&
!svc_sendreply(transp, xdr_result, result))
{
svcerr_systemerr(transp);
}
if (!svc_freeargs(transp, xdr_argument, &argument))
{
(void)fprintf(stderr, "UNABLE TO FREE ARGUMENTS\n");
exit(16);
}
return;
}
SORTCLNT
This is the source code listing for the sortclnt program:
/* @(#)rsort.c 2.1 88/08/11 4.0 RPCSRC */
#include <stdio.h>
#include <rpc.h>
#include <sort.h>
main(argc, argv)
int argc;
char **argv;
{
char *machinename;
struct sortstrings args;
struct sortstrings res;
int i;
if (argc < 3)
{
fprintf(stderr, "USAGE: %s MACHINENAME {S1 ...}\n", argv[0]);
exit(16);
}
machinename = argv[1];
args.ss.ss_len = argc - 2;
args.ss.ss_val = &argv[2];
res.ss.ss_val = (char **)NULL;
exit(0);
return(0);
}