home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / samples / sample9 / client.cpp next >
Text File  |  1997-04-03  |  1KB  |  59 lines

  1. #include "xheaders.h"
  2. #include XNamedPipeClient_i
  3. #include XNamedPipeServer_i
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8.  
  9. void main ( void)
  10. {
  11.    LONG res;
  12.  
  13.    //a client
  14.    XNamedPipeClient client;
  15.  
  16.    //open a pipe
  17.    if( (res = client.Open( "Sample9Pipe" )) != 0)
  18.       {
  19.          printf( "cannot open pipe, rc was: %i", res);
  20.          exit(0);
  21.       }
  22.  
  23.    //look for a server (max two seconds in this case)
  24.    client.WaitForServer( "Sampl9Pipe", 2000);
  25.  
  26.    if( !client.GetState() == XNPIPE_STATE_CONNECTED)         
  27.       {
  28.          printf( "not connected\n");
  29.          exit(0);
  30.       }
  31.  
  32.  
  33.    //try to read data
  34.    LONG i=0, buffer, result=0;
  35.    printf("got server\n");
  36.  
  37.    while( 1 )
  38.       {
  39.          result = 0;
  40.          printf( "Read data? (Y)es, (E)xit\n");
  41.          int key = getchar();
  42.          getchar();                       //remove carriage return
  43.          if (key == 'E' || key == 'e')
  44.             exit(0);
  45.          if(key == 'Y' || key == 'y')
  46.             {
  47.                for(i=0; i < 100; i++)
  48.                   {
  49.                      client.Read( buffer );
  50.                      result += buffer;
  51.                   }
  52.                printf( "data read: %li\n", result );
  53.             }
  54.       }
  55.  
  56.    //clean up
  57.    client.Close();
  58. }
  59.