home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PIPEDEME.ZIP / PCLIENT.C < prev    next >
C/C++ Source or Header  |  1990-05-30  |  1KB  |  92 lines

  1. /*
  2.  
  3.     PCLIENT.C - client (receive) half of named pipe demo.
  4.  
  5.     Copyright (C) 1990, by John D. Ruley @ Zaphodyne Inc.
  6.  
  7.     Unlimited right is herewith granted to use, modify and otherwise
  8.     exploit this software at will, however neither the author, nor
  9.     Zaphodyne Inc. shall bear ANY responsibility for the results!
  10.  
  11.     Compile with MSC 5.1 using MKPDEMO.CMD
  12.  
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. #define INCL_BASE
  19. #include <os2.h>
  20.  
  21. unsigned char far *buffer;
  22.  
  23. main(argc, argv)
  24. int argc;
  25. char *argv[];
  26. {
  27. HPIPE hp;
  28. USHORT n, action;
  29. int i;
  30.  
  31. if(argc < 2)
  32.     {
  33.     printf("useage pclient \\pipe\\PIPE_NAME");
  34.     exit(0);
  35.     }
  36.  
  37. /* make a data buffer: */
  38.  
  39. buffer = (unsigned char far *)malloc(64000);
  40. if(!buffer)
  41.     {
  42.     printf("ERROR - unable to allocate buffer space!\n");
  43.     exit(3);
  44.     }
  45.  
  46. /* open the pipe (server must have made it already): */
  47.  
  48. if((n = DosOpen(
  49.         argv[1],
  50.         &hp,
  51.         &action,
  52.         0L,
  53.         FILE_NORMAL,
  54.         FILE_OPEN,
  55.         OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
  56.         0L
  57.         )))
  58.     {
  59.     printf("ERROR %d opening pipe %s\n",n,argv[1]);
  60.     exit(1);
  61.     }
  62.  
  63. else{
  64.  
  65.     while(1)
  66.         {
  67.  
  68.     /* loop until user presses the ESCape key: */
  69.  
  70.         if(kbhit())
  71.             {
  72.             i = getch();
  73.             if(i == 27)break;
  74.             }
  75.  
  76.     /* read a 64K data block: */
  77.  
  78.         if(DosRead(hp, buffer, 64000, &n))break;
  79.         printf(".");
  80.         }
  81.  
  82.     /* all done: close the pipe: */
  83.  
  84.     DosClose(hp);
  85.     }
  86.  
  87. /* clean up & quit: */
  88.  
  89. free(buffer);
  90. printf("Done!\n");
  91. }
  92.