rpc簡介、原理、例項-緣於difx
阿新 • • 發佈:2019-01-23
/* * rtime.c: remote version * of "printime.c" */ #include <stdio.h> #include "time.h" /* time.h generated by rpcgen */ main(int argc, char **argv) { CLIENT *clnt; char *result; char *server; char *message; if (argc != 3) { fprintf(stderr, "usage: %s host messagen", argv[0]); exit(1); } server = argv[1]; message = argv[2]; /* * Create client "handle" used for * calling TIMEPROG on the server * designated on the command line. */ //clnt = clnt_create(server, TIMEPROG, PRINTIMEVERS, "visible"); clnt = clnt_create(server, TIMEPROG, PRINTIMEVERS, "TCP"); if (clnt == (CLIENT *)NULL) { /* * Couldn't establish connection * with server. * Print error message and die. */ clnt_pcreateerror(server); exit(1); } /* * Call the remote procedure * "printime" on the server */ result =*printime_1(&message,clnt); if (result== (char *)NULL) { /* * An error occurred while calling * the server. * Print error message and die. */ clnt_perror(clnt, server); exit(1); } /* Okay, we successfully called * the remote procedure. */ if (strcmp(result,"Error")==0){ /* * Server was unable to print * the time. * Print error message and die. */ fprintf(stderr, "%s: could not get the timen",argv[0]); exit(1); } printf("From the Time Server ...%s",result); clnt_destroy( clnt ); exit(0); }