Advertisement
piffy

pipe_client(Win)

Aug 31st, 2014
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4.  
  5.  
  6. const char nome[]="\\\\.\\pipe\\pippo";
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. HANDLE hpipe;
  11. BOOL bRet;
  12. DWORD size;
  13.  
  14. hpipe = CreateFile(nome,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
  15. if(hpipe==INVALID_HANDLE_VALUE)
  16.     {printf("Errore apertura file: %d\n",GetLastError());}
  17. while(1)
  18. {
  19. char messaggio [100];
  20. bRet = ReadFile(hpipe,messaggio,100,&size,NULL);
  21. if(bRet==FALSE)
  22.     {
  23. printf("Lettura fallita: letti %u byte.\n",size);
  24. break;
  25. }
  26.  
  27.     printf("Ricevuto dal server: %s\n",messaggio);
  28.     Sleep(500);
  29.     }
  30.  
  31. CloseHandle(hpipe);
  32. system("pause");
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement