Advertisement
piffy

pipe_client(Win,C++)

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