home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / n / n001 / 2.ddi / EXAMPLES / ASYNC1 / CLIENT / CLIENT.C next >
Encoding:
C/C++ Source or Header  |  1989-12-11  |  4.1 KB  |  136 lines

  1. /*                                                                            *
  2.  *                                                                            *
  3.  *                  Copyright 1987, 1988, 1989 Netwise, Inc.                  *
  4.  *                              All Rights Reserved                           *
  5.  *   This software contains information which is proprietary to and a trade   *
  6.  *   secret of Netwise, Inc. It is not to be used, reproduced, or disclosed   *
  7.  *   except as authorized in your license agreement.                          *
  8.  *                                                                            *
  9.  *                          Restricted Rights Legend                          *
  10.  *   Use, duplication,  or  disclosure  by the  Government  is  subject  to   *
  11.  *   restrictions as set forth in subparagraph (c)(1)(ii) of the Rights  in   *
  12.  *   Technical Data and  Computer Software clause  at 252.227-7013, or  the   *
  13.  *   equivalent Government clause for other agencies.                         *
  14.  *   Contractor: Netwise, Inc., Boulder, CO 80301 USA                         *
  15.  *                                                                            *
  16.  */ 
  17. /*
  18.  * File: async1\client\client.c
  19.  *
  20.  * This example works in the following environments:
  21.  *    NetWare RPC 1.0, NetWare 2.1 or higher, DOS 3.3
  22.  *
  23.  * This is the driver program for the async1 example. The purpose of this
  24.  * example is to illustrate the use of an non-blocking client stub. This 
  25.  * driver program is a C program which simply calls the remote procedures
  26.  * add and subtract and prints the result. poll_reply is called to see if
  27.  * the server has replied.
  28.  */
  29. #include <stdio.h>
  30. #include "async1.h"    /* client header file, created by the RPC compiler */
  31.  
  32. extern int _rpcerr_;    /* declare RPC error code */
  33.  
  34. /* Server_Name is used to set the process-binding variable.
  35.  * It must be defined as the name the server registers under.
  36.  */
  37. #define Server_Name  "example"
  38.  
  39. /* declare variable of type server_name for process binding */
  40. server_name sname;
  41.  
  42. main()
  43. {
  44.     int    arg1, arg2;
  45.     int    result;
  46.     int    erc;
  47.     char    *cli_rpc_handle;
  48.  
  49.     sname = Server_Name;
  50.  
  51.     /* Example of asynchronous call to add */
  52.     arg1 = 1234;
  53.     arg2 = 5678;
  54.     cli_rpc_handle = (char *)0;
  55.  
  56.     printf("CLIENT: calling add() with %d and %d\n", arg1, arg2);
  57.  
  58.     add(arg1, arg2, &cli_rpc_handle);
  59.  
  60.     for (;;) {
  61.         /*
  62.          * Poll to see if the server has replied.
  63.          */
  64.         erc = poll_reply(cli_rpc_handle);
  65.  
  66.         if (erc == 1)
  67.             /* reply message received from remote procedure */
  68.             break;
  69.         else if (erc == 0) {
  70.             printf("No result yet, try again\n");
  71.         } else {
  72.             /* error from poll_reply(); continue so state
  73.              * machine in client stub can clean up
  74.              */
  75.             printf("CLIENT: error %d in poll_reply()\n", erc);
  76.             break;
  77.         }
  78.             
  79.     }
  80.  
  81.     /*
  82.      * Now that the server has replied, call add again to
  83.      * complete the asynchronous remote procedure call.
  84.      */
  85.     result = add(arg1,arg2, &cli_rpc_handle);
  86.  
  87.     if (_rpcerr_) {        /* check RPC error code */
  88.         printf("CLIENT: RPC error %d in add() call\n", _rpcerr_);
  89.         exit(1);
  90.     }
  91.     printf("CLIENT: add() returned %d\n\n", result);
  92.  
  93.     /* Example of asynchronous call to sub() */
  94.     arg1 = result;
  95.     arg2 = 5678;
  96.     cli_rpc_handle = (char *)0;
  97.  
  98.     printf("CLIENT: calling sub() with %d and %d\n", arg1, arg2);
  99.  
  100.     sub(arg1, arg2, &cli_rpc_handle);
  101.  
  102.     for (;;) {
  103.         /*
  104.          * Poll to see if the server has replied.
  105.          */
  106.         erc = poll_reply(cli_rpc_handle);
  107.  
  108.         if (erc == 1)
  109.             /* reply message received from remote procedure */
  110.             break;
  111.         else if (erc == 0) {
  112.             printf("No result yet, try again\n");
  113.         } else {
  114.             /* error from poll_reply(); continue so state
  115.              * machine in client stub can clean up
  116.              */
  117.             printf("CLIENT: error %d in poll_reply()\n", erc);
  118.             break;
  119.         }
  120.     }
  121.  
  122.     /*
  123.      * Now that the server has replied, call sub again to
  124.      * complete the asynchronous remote procedure call.
  125.      */
  126.     result = sub(arg1, arg2, &cli_rpc_handle);
  127.  
  128.     if (_rpcerr_) {        /* check RPC error code */
  129.         printf("CLIENT: RPC error %d in sub() call\n", _rpcerr_);
  130.         exit(1);
  131.     }
  132.     printf("CLIENT: sub() returned %d\n\n", result);
  133.  
  134.     exit(0);
  135. }
  136.