home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / examples / rpc / msg / rprintmsg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-09  |  1.5 KB  |  73 lines

  1. /* @(#)rprintmsg.c    2.1 88/08/11 4.0 RPCSRC */
  2. /*
  3.  * rprintmsg.c: remote version of "printmsg.c"
  4.  */
  5. #include <stdio.h>
  6. #include <rpc/rpc.h>        /* always need this */
  7. #include "msg.h"        /* need this too: will be generated by rpcgen*/
  8.  
  9. main(int argc, char **argv)
  10. {
  11.     CLIENT *cl;
  12.     int *result;
  13.     char *server;
  14.     char *message;
  15.  
  16.     if (argc < 3) {
  17.         fprintf(stderr, "usage: %s host message\n", argv[0]);
  18.         exit(1);
  19.     }
  20.  
  21.     /*
  22.      * Remember what our command line arguments refer to
  23.      */
  24.     server = argv[1];
  25.     message = argv[2];
  26.  
  27.     /*
  28.      * Create client "handle" used for calling MESSAGEPROG on the
  29.      * server designated on the command line. We tell the rpc package
  30.      * to use the "tcp" protocol when contacting the server.
  31.      */
  32.     cl = clnt_create(server, MESSAGEPROG, MESSAGEVERS, "tcp");
  33.     if (cl == NULL) {
  34.         /*
  35.          * Couldn't establish connection with server.
  36.          * Print error message and die.
  37.          */
  38.         clnt_pcreateerror(server);
  39.         exit(1);
  40.     }
  41.     
  42.     /*
  43.      * Call the remote procedure "printmessage" on the server
  44.      */
  45.     result = printmessage_1(&message, cl);
  46.     if (result == NULL) {
  47.         /*
  48.          * An error occurred while calling the server. 
  49.           * Print error message and die.
  50.          */
  51.         clnt_perror(cl, server);
  52.         exit(1);
  53.     }
  54.  
  55.     /*
  56.      * Okay, we successfully called the remote procedure.
  57.      */
  58.     if (*result == 0) {
  59.         /*
  60.          * Server was unable to print our message. 
  61.          * Print error message and die.
  62.          */
  63.         fprintf(stderr, "%s: sorry, %s couldn't print your message\n", 
  64.             argv[0], server);    
  65.         exit(1);
  66.     } 
  67.  
  68.     /*
  69.      * The message got printed on the server's console
  70.      */
  71.     printf("Message delivered to %s!\n", server);
  72. }
  73.