home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / n / n001 / 2.ddi / EXAMPLES / FREEMEM / CLIENT / CLIENT.C next >
Encoding:
C/C++ Source or Header  |  1989-12-11  |  3.1 KB  |  89 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: freemem\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 freemem example. This example 
  24.  * demonstrates dynamic allocation of memory by the client RPC
  25.  * code and the remote procedure.
  26.  */
  27.  
  28. #include <stdio.h>
  29. #include "freemem.h"    /* client header file, created by the RPC compiler */
  30.  
  31. extern int _rpcerr_;    /* declare RPC error code */
  32.  
  33. /* Server_Name is used to set the process-binding variable.
  34.  * It must be defined as the name the server registers under.
  35.  */
  36. #define Server_Name  "example"
  37.  
  38. /* declare variable of type server_name for process binding */
  39. server_name sname;
  40.  
  41. char *string;
  42.  
  43. main()
  44. {
  45.     int result;
  46.  
  47.     sname = Server_Name;
  48.     
  49.     string = (char *)0;
  50.  
  51.     /* example of call to remote procedure get_string() */
  52.     printf("CLIENT: calling get_string(15)\n");
  53.     result = get_string(15);
  54.  
  55.     if (_rpcerr_) {        /* check RPC return code */
  56.         printf("CLIENT: RPC error %d in get_string() call\n",
  57.             _rpcerr_);
  58.         exit(1);
  59.     }
  60.  
  61.     printf("CLIENT: get_string(%d) returned '%s'\n", 15, string);
  62.  
  63.     /* Memory for 'string' was dynamically allocated by the client
  64.        stub code.  Therefore, the client application must call
  65.        free() to de-allocate this memory when it is no longer needed. */
  66.  
  67.     free(string);
  68.  
  69.     /* another example of call to remote procedure get_string() */
  70.     printf("CLIENT: calling get_string(123)\n");
  71.     result = get_string(123);
  72.  
  73.     if (_rpcerr_) {        /* check RPC return code */
  74.         printf("CLIENT: RPC error %d in get_string() call\n",
  75.             _rpcerr_);
  76.         exit(1);
  77.     }
  78.  
  79.     printf("CLIENT: get_string(%d) returned '%s'\n", 123, string);
  80.  
  81.     /* Memory for 'string' was dynamically allocated by the client
  82.        stub code.  Therefore, the client application must call
  83.        free() to de-allocate this memory when it is no longer needed. */
  84.  
  85.     free(string);
  86.     
  87.     exit(0);
  88. }
  89.