DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with Remote Procedure Calls (RPC)

Low-level program testing using raw RPC

There are two pseudo-RPC interface routines provided to support program testing. These routines, clnt_raw_create and svc_raw_create, do not involve the use of any real transport. They exist to help the developer debug and test the non-communications-oriented aspects of an application before running it over a real network.

This is an example of their use:

   /*
    * A simple program to increment a number by 1
    */
   #include <stdio.h>
   #include <rpc/rpc.h>
   #include <rpc/raw.h>
   

struct timeval TIMEOUT = {0, 0}; static void server();

main (argc, argv) int argc; char **argv; { CLIENT *cl; SVCXPRT *svc; int num = 0, ans;

if (argc == 2) num = atoi(argv[1]); svc = svc_raw_create(); if (svc == NULL) { fprintf(stderr, "Could not create server handle\n"); exit(1); } svc_reg(svc, 200000, 1, server, 0); cl = clnt_raw_create(200000, 1); if (cl == NULL) { clnt_pcreateerror("raw"); exit(1); } if (clnt_call(cl, 1, xdr_int, &num, xdr_int, &ans, TIMEOUT) != RPC_SUCCESS) { clnt_perror(cl, "raw"); exit(1); } printf("Client: number returned %d\n", ans); exit(0) ; }

static void server(rqstp, transp) struct svc_req *rqstp; SVCXPRT *transp; { int num;

switch(rqstp->rq_proc) { case 0: if (svc_sendreply(transp, xdr_void, 0) == NULL) { fprintf(stderr, "error in null proc\n"); exit (1); } return; case 1: break; default: svcerr_noproc(transp); return; } if (!svc_getargs(transp, xdr_int, &num)) { svcerr_decode(transp); return; } num++; if (svc_sendreply(transp, xdr_int, &num) == NULL) { fprintf(stderr, "error in sending answer\n"); exit (1); } return; }

Note the following points:
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005