SERVER.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:4k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*************************************************************/
  2. /**                                                         **/
  3. /**                 Microsoft RPC Examples                  **/
  4. /**                 Dictionary Application                  **/
  5. /**          Copyright(c) Microsoft Corp. 1992-1996         **/
  6. /**                                                         **/
  7. /*************************************************************/
  8. /*
  9.  *************************************************************************
  10.  *                                                                       *
  11.  * Remote dictionary example: server side                                *
  12.  *                                                                       *
  13.  * Description:                                                          *
  14.  * This is the driver for the server side remote dictionary              *
  15.  * (splay trees based) demo.  This is a standard server driver,          *
  16.  * and it works as follows:                                              *
  17.  *                                                                       *
  18.  *  o Call RpcCreateServer to initialize all data structures             *
  19.  *                                                                       *
  20.  *  o Initialize an appropriate protocol stack                           *
  21.  *                                                                       *
  22.  *  o Call RpcAddAddress to start listening on a transport address       *
  23.  *    (a named pipe in our case).                                        *
  24.  *                                                                       *
  25.  *  o Call RpcAddInterface to initialize interface specific structures   *
  26.  *    (such as dispatch table, etc.)                                     *
  27.  *                                                                       *
  28.  *  o Optionally advertise by calling RpcExport (not in this version)    *
  29.  *                                                                       *
  30.  *  o Loop forever...                                                    *
  31.  *                                                                       *
  32.  *************************************************************************
  33. */
  34. #include <stdlib.h>
  35. #include <stdio.h>
  36. #include <ctype.h>
  37. #include "replay.h"    // header file generated by MIDL compiler
  38. #include "dict0.h"
  39. #include "util0.h"
  40. void Usage()
  41. {
  42.   printf("Usage : server -e <endpoint>n");
  43.   exit(1);
  44. }
  45. void _CRTAPI1
  46. main(int argc, char *argv[])
  47. {
  48.     RPC_STATUS status;
  49.     unsigned char * pszProtocolSequence = "ncacn_np";
  50.     unsigned char * pszSecurity         = NULL;
  51.     unsigned char * pszEndpoint         = "\pipe\dict";
  52.     unsigned int    cMinCalls           = 1;
  53.     unsigned int    cMaxCalls           = 20;
  54.     unsigned int    fDontWait           = FALSE;
  55.     int i;
  56.     printf ("Microsoft RPC demo Server - Splay (Binary) Tree DataBasen");
  57.     /* allow the user to override settings with command line switches */
  58.     for (i = 1; i < argc; i++) {
  59.         if ((*argv[i] == '-') || (*argv[i] == '/')) {
  60.             switch (tolower(*(argv[i]+1))) {
  61.             case 'e':
  62.                 pszEndpoint = argv[++i];
  63.                 break;
  64.             case 'h':
  65.             case '?':
  66.             default:
  67.                 Usage();
  68.             }
  69.         }
  70.         else
  71.             Usage();
  72.     }
  73.     status = RpcServerUseProtseqEp(pszProtocolSequence,
  74.                                    cMaxCalls,
  75.                                    pszEndpoint,
  76.                                    pszSecurity);  // Security descriptor
  77.     if (status) {
  78.         printf("RpcServerUseProtseqEp returned 0x%xn", status);
  79.         exit(status);
  80.     }
  81.     status = RpcServerRegisterIf(dict_ServerIfHandle,  // interface to register
  82.                                  NULL,   // MgrTypeUuid
  83.                                  NULL);  // MgrEpv; null means use default
  84.     if (status) {
  85.         printf("RpcServerRegisterIf returned 0x%xn", status);
  86.         exit(status);
  87.     }
  88.     printf("Calling RpcServerListenn");
  89.     status = RpcServerListen(cMinCalls,
  90.                              cMaxCalls,
  91.                              fDontWait);
  92.     if (status) {
  93.         printf("RpcServerListen returned: 0x%xn", status);
  94.         exit(status);
  95.     }
  96. }