#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 *numptr; stringdata parms; /* defined in countchar.x */ nextcount *countlist, list; buftype bufptr; 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 */ printf("Getting ready to call countchar\n"); parms.findch = *argv[3]; parms.buf = argv[2]; /* Count occurences of given character */ numptr = countchar_1(&parms,cl); printf("Back from countchar\n"); if (numptr == NULL) { clnt_perror(cl,argv[1]); exit(1); } printf("Returned count=%d\n",*numptr); /* RPC CALL 2 -- invoke countallchars */ printf("Getting ready to call countallchars\n");fflush(stdout); bufptr = argv[2]; countlist = countallchars_1(&bufptr,cl); printf("Back from call, countlist=%x\n",countlist);fflush(stdout); if (countlist == NULL) { 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); }