#include #include #include "countchar.h" /* Generated by rpcgen */ /* CpSc 824 Desc: example of Client program that calls the countchar rpc on a remote node. Usage: countmain node character-string character where: node is the remote node to execute this on, character_string is the string to be searched, character is the string to be searched for. */ main (argc,argv) int argc; char *argv[]; { CLIENT *cl; int numResult; stringdata parms; /* defined in countchar.x */ nextcount countlist, list; buftype bufptr; enum clnt_stat retval; if (argc != 4 ) { printf("Usage: countmain node character-string character\n"); exit(1); } /* Set up connection to server */ cl = clnt_create(argv[1], COUNTCHARPROG, COUNTVERS, "tcp"); if (cl == NULL) { clnt_pcreateerror(argv[1]); exit(1); } /* RPC CALL 1 -- invoke countchar */ parms.findch = *argv[3]; parms.buf = argv[2]; /* Count occurences of given character */ retval = countchar_1(&parms, &numResult, cl); if (retval != RPC_SUCCESS) { clnt_perror(cl,argv[1]); exit(1); } printf("Returned count=%d\n",numResult); fflush(stdout); /* RPC CALL 2 -- invoke countallchars */ bufptr = argv[2]; countlist = NULL; retval = countallchars_1(&bufptr, &countlist, cl); if (retval != RPC_SUCCESS) { clnt_perror(cl,argv[1]); exit(1); } /* Output returned list */ list = countlist; while (list) { printf("Character %c: %d\n", list->character, list->count); list = list->next; } /* Free result list */ if (clnt_freeres(cl, (xdrproc_t) xdr_nextcount, (caddr_t) &countlist)!=1) { printf("clnt_freeres failed\n"); }; printf("Done\n");fflush(stdout); }