fork download
  1. /* filename: pipe_server.c */
  2.  
  3. #define UNICODE
  4.  
  5. #include <windows.h>
  6. #include <stdio.h>
  7.  
  8. int main() {
  9. wchar_t buf[1024];
  10. int numBytes = 0;
  11. BOOL writeGood = FALSE;
  12.  
  13. HANDLE hPipe = NULL;
  14. hPipe = CreateNamedPipe(L"\\\\.\\pipe\\purpose",
  15. PIPE_ACCESS_DUPLEX,
  16. PIPE_TYPE_BYTE,
  17. 1,
  18. 512, /* out-buf size */
  19. 512, /* in-buf size */
  20. 0,
  21. NULL);
  22.  
  23. if (hPipe == INVALID_HANDLE_VALUE) {
  24. _putws(L"hPipe error.\n");
  25. return 0;
  26. }
  27.  
  28. puts("server is listening...");
  29. if (ConnectNamedPipe(hPipe, NULL) == TRUE) {
  30. writeGood = WriteFile(hPipe, L"^_^", 8, &numBytes, NULL);
  31. printf("numBytes for writefile = %d\n", numBytes);
  32. if (writeGood == FALSE) return 0;
  33.  
  34. _putws(L"sleeping...");
  35. Sleep(8000);
  36.  
  37. writeGood = WriteFile(hPipe, L">_<", 8, &numBytes, NULL);
  38. printf("numBytes for writefile = %d\n", numBytes);
  39. if (writeGood == FALSE) return 0;
  40.  
  41. ReadFile(hPipe,
  42. buf,
  43. 1024 * sizeof(wchar_t),
  44. &numBytes,
  45. NULL);
  46. printf("numBytes for readfile = %d\n", numBytes);
  47. _putws(buf);
  48. }
  49.  
  50. FlushFileBuffers(hPipe);
  51. DisconnectNamedPipe(hPipe);
  52. CloseHandle(hPipe);
  53. return 0;
  54. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty