home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / n / n001 / 2.ddi / EXAMPLES / PERSIST / CLIENT / CLIENT.C next >
Encoding:
C/C++ Source or Header  |  1989-12-11  |  3.8 KB  |  117 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: perist\client\client.c
  19.  *
  20.  * This example runs in the following environments:
  21.  *    NetWare RPC 1.0, NetWare 2.1 or higher, DOS 3.3
  22.  *
  23.  * Client code for the persist example.  A connection is established,
  24.  * two remote procedure calls are made, then the connection is closed.
  25.  * Persistent connections save on overhead associated with connection
  26.  * establishment and closing.
  27.  *
  28.  */ 
  29.  
  30. #include <stdio.h>
  31. #include "persist.h"    /* client header file, created by RPC compiler */
  32.  
  33. extern int _rpcerr_;     /* declare RPC error code */
  34.  
  35. /* Server_Name is used to set the process-binding variable.
  36.  * It must be defined as the name the server registers under.
  37.  */
  38. #define Server_Name "example"
  39.  
  40. /* declare variable of type server_name for process binding */
  41. server_name sname;
  42.  
  43. /* declare variable of type connection_id for process binding
  44.  * for a persistent connection.
  45.  */
  46. connection_id conn;
  47.  
  48. main()
  49. {
  50.     int arg1, arg2;
  51.     int result;
  52.     int i;
  53.  
  54.     sname = Server_Name;
  55.  
  56.     /* Establish connection using start procedure */
  57.  
  58.     printf("CLIENT: attempting to establish a connection\n");
  59.     result = start(sname);
  60.  
  61.     if (_rpcerr_) {        /* check RPC return code */
  62.         printf("CLIENT: RPC error %d in start() call\n", _rpcerr_);
  63.         exit(1);
  64.     }
  65.     printf("CLIENT: connection established\n");
  66.  
  67.     /* "sleep" for a while */
  68.     printf("CLIENT: sleeping\n");
  69.     {int isleep; for (isleep=0; isleep<=30000; isleep++);}
  70.  
  71.     /* example of call to add() using established connection */
  72.  
  73.     arg1=1234;
  74.     arg2=5678;
  75.     printf("CLIENT: calling add() with %d and %d\n", arg1, arg2);
  76.     result = add(arg1,arg2);
  77.  
  78.     if (_rpcerr_) {        /* check RPC return code */
  79.         printf("CLIENT: RPC error %d in add() call\n", _rpcerr_);
  80.         exit(1);
  81.     }
  82.     printf("CLIENT: add() returned %d\n\n", result);
  83.  
  84.     /* "sleep" for a while */
  85.     printf("CLIENT: sleeping\n");
  86.     {int isleep; for (isleep=0; isleep<=30000; isleep++);}
  87.  
  88.     /* example of call to sub() using established connection */
  89.  
  90.     arg1=result;
  91.     arg2=5678;
  92.     printf("CLIENT: calling sub() with %d and %d\n", arg1, arg2);
  93.     result = sub(arg1,arg2);
  94.  
  95.     if (_rpcerr_) {        /* check RPC return code */
  96.         printf("CLIENT: RPC error %d in sub() call\n", _rpcerr_);
  97.         exit(1);
  98.     }
  99.     printf("CLIENT: sub() returned %d\n\n", result);
  100.  
  101.     /* "sleep" for a while */
  102.     printf("CLIENT: sleeping\n");
  103.     {int isleep; for (isleep=0; isleep<=30000; isleep++);}
  104.  
  105.     /* Close connection using stop procedure */
  106.     printf("CLIENT: attempting to close connection\n");
  107.     result = stop();
  108.  
  109.     if (_rpcerr_) {        /* check RPC return code */
  110.         printf("CLIENT: RPC error %d in stop() call\n", _rpcerr_);
  111.         exit(1);
  112.     }
  113.     printf("CLIENT: connection closed\n");
  114.  
  115.     exit(0);
  116. }
  117.