Advertisement
piffy

pipe_server(Win)

Aug 31st, 2014
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4.  
  5. const char nome[]="\\\\.\\pipe\\pippo";
  6.  
  7. void ConnectToClient(HANDLE hpipe){
  8. int i;DWORD dwWrite;
  9. BOOL bRet;FILE *f;
  10. f = fopen("testo.txt","r");
  11.  
  12. if(ConnectNamedPipe(hpipe,NULL)==0)
  13.     {printf("Errore di connessione al client: \n");}
  14. while (feof(f) == 0)
  15. {
  16.  char messaggio [100];
  17.  fgets(messaggio,100,f);
  18.  bRet = WriteFile(hpipe,messaggio,sizeof(messaggio),&dwWrite,NULL);
  19.  if(bRet==FALSE)
  20.     {printf("Errore di scrittura nella pipe: \n"); }
  21. }
  22. Sleep(5000);
  23. DisconnectNamedPipe(hpipe);
  24. }
  25.  
  26. int main(int argc, char *argv[])
  27. {
  28. HANDLE hpipe;
  29. hpipe = CreateNamedPipe(nome,PIPE_ACCESS_OUTBOUND|FILE_FLAG_WRITE_THROUGH,
  30.                PIPE_TYPE_MESSAGE|PIPE_WAIT,PIPE_UNLIMITED_INSTANCES,512,512,1000,NULL);
  31. if(hpipe==INVALID_HANDLE_VALUE)
  32.     {printf("Errore apertura pipe: %d\n",GetLastError());}
  33. ConnectToClient(hpipe);
  34. CloseHandle(hpipe);
  35. system("pause");
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement