home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / EDMI2.ZIP / CLNTSRV.ZIP / server.c < prev    next >
C/C++ Source or Header  |  1993-03-21  |  1KB  |  62 lines

  1. #define INCL_ERRORS
  2. #define INCL_DOS
  3. #include <os2.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. #define PROGNAME "server"
  9. #define PIPE_NAME "\\pipe\\sembatch\\server"
  10. #define MESSAGE_SIZE 128
  11. #define BUF_SIZE 1024
  12.  
  13. typedef char *pchar, **ppchar;
  14.  
  15. void error_check(char *string,int i) {
  16.     if (i) {
  17.         printf ("Error %d!!!\n%s\n",i,string);
  18.         exit(-1);
  19.     }
  20. }
  21.  
  22. void main (void) {
  23.     HPIPE hpHandle;
  24.     CHAR pszInBuf[MESSAGE_SIZE],pszOutBuf[MESSAGE_SIZE];
  25.     ULONG ulBytes;
  26.     USHORT rc;
  27.     
  28.     setbuf(stdout,NULL);
  29.     rc=DosCreateNPipe(PIPE_NAME,
  30.                       &hpHandle,
  31.                       NP_ACCESS_DUPLEX | NP_NOWRITEBEHIND,
  32.                       NP_WAIT | NP_TYPE_BYTE | NP_READMODE_BYTE | 1,
  33.                       BUF_SIZE,
  34.                       BUF_SIZE,
  35.                       0);
  36.     error_check("DosCreateNPipe",rc);
  37.     while (1) {
  38.         rc=DosConnectNPipe(hpHandle);
  39.         error_check("DosConnectNPipe",rc);
  40.  
  41.         rc=DosRead(hpHandle,pszInBuf,MESSAGE_SIZE,&ulBytes);
  42.         error_check("DosRead",rc);
  43.         
  44.         printf("read:%s\n",pszInBuf);
  45.         strcpy(pszOutBuf,pszInBuf);
  46.         
  47.         rc=DosWrite(hpHandle,pszOutBuf,MESSAGE_SIZE,&ulBytes);
  48.         error_check("DosWrite",rc);
  49.         printf("wrote:%s\n",pszOutBuf);
  50.  
  51. /*        rc=DosResetBuffer(hpHandle);
  52.         if (rc!=ERROR_BROKEN_PIPE)
  53.             error_check("DosResetBuffer",rc);
  54. */
  55.         rc=DosRead(hpHandle,pszOutBuf,1,&ulBytes);
  56.         if (ulBytes!=0) error_check("DosRead:EOF check",rc);
  57.         
  58.         rc=DosDisConnectNPipe(hpHandle);
  59.         error_check("DosDisConnectNPipe",rc);
  60.     }
  61. }
  62.