home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / greetz.zip / client.c next >
Text File  |  1993-11-08  |  3KB  |  95 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "greet.h"
  5.  
  6. int main(int ac, char*av[])
  7. {
  8.     handle_t                 h;
  9.     error_status_t           st, error_inq_st;
  10.     idl_char                 *string_binding;
  11.     int                      i, MAX_PASS;
  12.     char                     server_reply[STR_SZ], error_string [1024],
  13.                              *server_name;
  14.     rpc_ns_import_handle_t   import_context;
  15.  
  16.  
  17.     if (ac != 2)  {
  18.         printf("Usage: %s passes\n", av[0]);
  19.         exit (1);
  20.     }
  21.  
  22.  
  23.     /* import compatible server bindings from the namespace */
  24.  
  25.     rpc_ns_binding_import_begin(rpc_c_ns_syntax_dce,
  26.                                 "/.:/servers/greet", greet_v1_0_c_ifspec,
  27.                                (uuid_t *)NULL, &import_context, &st);
  28.     printf("rpc_ns_binding_import_begin status is %x\n", st);
  29.  
  30.     if (st != error_status_ok) {
  31.         dce_error_inq_text(st, error_string, &error_inq_st);
  32.         fprintf(stderr, "dce_error_inq_text status is %x\n", error_inq_st);
  33.         fprintf(stderr, "Cannot begin importing binding - %s\n",
  34.                 error_string);
  35.         exit(1);
  36.        }
  37.  
  38.     /* sift through bindings and choose the first one over udp */
  39.     /***************************************************************
  40.     For the OS/2 DCE Toolkit rel:  RPC only works over UDP right now
  41.     ***************************************************************/
  42.  
  43.     while (1) {
  44.         rpc_ns_binding_import_next(import_context, &h, &st);
  45.         printf("rpc_ns_binding_import_next status is %x\n", st);
  46.         if (st == rpc_s_no_more_bindings) {
  47.            dce_error_inq_text(st, error_string, &error_inq_st);
  48.            fprintf(stderr, "Cannot find binding over udp: %s\n",
  49.                    error_string);
  50.            exit(1);
  51.         }
  52.  
  53.          rpc_binding_to_string_binding(h, &string_binding, &st);
  54.          printf("rpc_binding_to_string_binding status is %x\n", st);
  55.          if (st != error_status_ok) {
  56.             dce_error_inq_text(st, error_string, &error_inq_st);
  57.             fprintf(stderr,
  58.                     "Cannot convert binding to string binding: %s\n",
  59.                     error_string);
  60.             exit(1);
  61.          }
  62.  
  63.          /* out of curiosity, print the binding */
  64.  
  65.          if (strstr(string_binding, "ncadg_ip_udp") != 0) {
  66.              printf("Client bound to server %s at %s\n",
  67.              "/.:/servers/greet", string_binding);
  68.              rpc_string_free(&string_binding, &st);
  69.              break;
  70.           }
  71.        }
  72.  
  73.    /* end the binding import lookup loop */
  74.  
  75.    rpc_ns_binding_import_done(&import_context, &st);
  76.    printf("rpc_ns_binding_import_done status is %x\n", st);
  77.    if (st != error_status_ok) {
  78.        dce_error_inq_text(st, error_string, &error_inq_st);
  79.        fprintf(stderr, "Cannot end binding import: %s\n",
  80.                error_string);
  81.        exit(1);
  82.    }
  83.  
  84.     printf("\n");
  85.  
  86.     MAX_PASS= atoi(av[1]);
  87.  
  88.          for (i=1; i <= MAX_PASS; i++) {
  89.              printf("greet_rpc call for pass %d is next\n", i);
  90.              greet_rpc(h, "Hello Server !", server_reply);
  91.              printf("The Greet Server said: %s\n", server_reply);
  92.           }
  93.  
  94. }
  95.