home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / rpc / interop / client.c next >
Encoding:
C/C++ Source or Header  |  1996-06-12  |  4.1 KB  |  135 lines

  1. /*************************************************************/
  2. /**                                                         **/
  3. /**                 Microsoft RPC Examples                  **/
  4. /**                 OSF DCE Sample Application              **/
  5. /**           Copyright(c) Microsoft Corp. 1992-1996        **/
  6. /**                                                         **/
  7. /*************************************************************/
  8.  
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13.  
  14. #include "msg.h"        /* header file generated by M/IDL compiler */
  15.  
  16. #if defined(__RPC_WIN32__) || defined(__RPC_DOS__)
  17.  
  18. /*
  19.  On MS platforms we must include the dceport.h header file
  20.  which maps OSF DCE style APIs to MS style APIs.
  21. */
  22.  
  23. #include "dceport.h"
  24.  
  25. #else
  26. #include <pthread.h>
  27. #endif
  28.  
  29. #ifndef _CRTAPI1
  30. #define _CRTAPI1
  31. #endif
  32.  
  33. void Usage()
  34. {
  35.   printf("Usage : client -n <server_name>\n");
  36.   printf("               -t <transport>   - optional, default ncacn_ip_tcp\n");
  37.   printf("               -e <endpoint>    - optional, should match server\n");
  38.   printf("               -s <message>     - optional, send a different message\n");
  39.   printf("               -x               - use to stop the server\n");
  40.   exit(1);
  41. }
  42.  
  43. int _CRTAPI1
  44. main(int argc, char *argv[])
  45. {
  46.     unsigned32 status;
  47.     unsigned char * pszProtocolSequence = (unsigned char *)"ncacn_ip_tcp";
  48.     unsigned char * pszNetworkAddress   = NULL;
  49.     unsigned char * pszEndpoint         = NULL;
  50.     unsigned char * pszStringBinding    = NULL;
  51.     unsigned char * pszMessage          = (unsigned char *)"Hello World";
  52.     int fStopServer = 0;
  53.     int i;
  54.  
  55.     printf ("Microsoft RPC Demo - OSF DCE Interop Message Client\n");
  56.  
  57.     for (i = 1; i < argc; i++) {
  58.         if ((*argv[i] == '-') || (*argv[i] == '/')) {
  59.             switch (tolower(*(argv[i]+1))) {
  60.             case 'n':  /* network address */
  61.                 pszNetworkAddress = (unsigned char *)argv[++i];
  62.                 break;
  63.             case 't':  /* protocol sequence */
  64.                 pszProtocolSequence = (unsigned char *)argv[++i];
  65.                 break;
  66.             case 'e':  /* network endpoint */
  67.                 pszEndpoint = (unsigned char *)argv[++i];
  68.                 break;
  69.             case 's':  /* update message */
  70.                 pszMessage = (unsigned char *)argv[++i];
  71.                 break;
  72.             case 'x':  /* stop the server */
  73.                 fStopServer = 1;
  74.                 break;
  75.             case 'h':
  76.             case '?':
  77.             default:
  78.                 Usage();
  79.             }
  80.         }
  81.         else
  82.             Usage();
  83.     }
  84.  
  85.     rpc_string_binding_compose(0,   /* no object uuid */
  86.                                pszProtocolSequence,
  87.                                pszNetworkAddress,
  88.                                pszEndpoint,
  89.                                0,  /* no options */
  90.                                &pszStringBinding,
  91.                                &status);
  92.     if (status) {
  93.         printf("rpc_string_binding_compose returned 0x%x\n", status);
  94.         return(status);
  95.     }
  96.  
  97.     rpc_binding_from_string_binding(pszStringBinding,
  98.                                     &interop_binding_handle,
  99.                                     &status);
  100.     if (status) {
  101.         printf("rpc_binding_from_string_binding returned 0x%x\n", status);
  102.         return(status);
  103.     }
  104.  
  105.     rpc_string_free(&pszStringBinding,&status);
  106.     if (status) {
  107.         printf("rpc_string_free returned 0x%x\n", status);
  108.         return(status);
  109.     }
  110.  
  111.     TRY {
  112.        ClientMessage(pszMessage);
  113.  
  114.        printf("Message sent okay\n");
  115.        if (fStopServer)
  116.            {
  117.            ShutdownServer();
  118.            printf("Server shutdown\n");
  119.            }
  120.     }
  121.     CATCH_ALL {
  122.        printf("RPC raised exception 0x%x\n", THIS_CATCH);
  123.     }
  124.     ENDTRY
  125.  
  126.     rpc_binding_free(&interop_binding_handle, &status);
  127.     if (status) {
  128.         printf("rpc_binding_free returned 0x%x\n", status);
  129.         return(status);
  130.     }
  131.  
  132.     return(0);
  133. }
  134.  
  135.