Source.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //ĘÎÄ ĘËČĹÍŇŔ
  2. // Đŕçäĺëčňü íŕ 2 ďđîĺęňŕ
  3. #define _CRT_SECURE_NO_WARNINGS
  4. #include <Stdio.h>
  5. #include <Windows.h>
  6. int main()
  7. {
  8. system("chcp 1251");
  9. BOOL flag_awser = TRUE;
  10. char message[100];
  11. DWORD read_buffer = 100;
  12. DWORD actual_read;
  13. DWORD actual_write;
  14. LPWSTR buffer = (CHAR*)calloc(read_buffer, sizeof(char));
  15. HANDLE hNamePipe;
  16. LPSTR pipeName = L"\\\\.\\pipe\\MyPipe";
  17. BOOL SuccessRead;
  18. BOOL isSuccess;
  19. DWORD dwMode = PIPE_READMODE_MESSAGE;
  20. while (1)
  21. {
  22. hNamePipe = CreateFile(pipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
  23. isSuccess = SetNamedPipeHandleState(hNamePipe, &dwMode, NULL, NULL);
  24. if (!isSuccess) {
  25. printf("\nŃĺđâĺđ íĺ îňâĺ÷ŕĺň\n");
  26. flag_awser = TRUE;
  27. }
  28. else
  29. {
  30. if (flag_awser) {
  31. printf("Ââĺäčňĺ ńîîáůĺíčĺ äë˙ ńĺđâĺđŕ: \n");
  32. gets(message);
  33. buffer = &message;
  34. WriteFile(hNamePipe, buffer, read_buffer, &actual_write, NULL);
  35. flag_awser = FALSE;
  36. }
  37. SuccessRead = ReadFile(hNamePipe, buffer, 100, &actual_read, NULL);
  38. if (SuccessRead) {
  39. printf("\nŃĺđâĺđ ďčřĺň: ");
  40. printf(buffer);
  41. printf("\n");
  42. flag_awser = TRUE;
  43. if (buffer == NULL)
  44. printf("Ďóńňî");
  45. }
  46. }
  47. Sleep(100);
  48. CloseHandle(hNamePipe);
  49. }
  50. }
  51. //ĘÎÄ ŃĹĐÂĹĐŔ
  52. #include <Stdio.h>
  53. #include <Windows.h>
  54. int main()
  55. {
  56. system("chcp 1251");
  57. HANDLE hNamePipe;
  58. LPSTR pipeName = L"\\\\.\\pipe\\MyPipe";
  59. DWORD read_buffer = 100;
  60. LPWSTR buffer = calloc(read_buffer, sizeof(char));
  61. char message[100];
  62. DWORD actual_read;
  63. BOOL Connected;
  64. BOOL SuccessRead;
  65. while (1)
  66. {
  67. hNamePipe = CreateNamedPipe(
  68. pipeName,
  69. PIPE_ACCESS_DUPLEX,
  70. PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
  71. PIPE_UNLIMITED_INSTANCES,
  72. 512,
  73. 512,
  74. INFINITE,
  75. NULL);
  76. Connected = ConnectNamedPipe(hNamePipe, NULL);
  77. if (Connected) {
  78. printf("\nĘëčĺíň ďîäęëţ÷čëń˙\n");
  79. SuccessRead = ReadFile(hNamePipe, buffer, read_buffer, &actual_read, NULL);
  80. if (SuccessRead) {
  81. printf("\nĘëčĺíň ďčřĺň: ");
  82. printf(buffer);
  83. printf("\n");
  84. printf("\nÂâĺäčňĺ ńîîáůĺíčĺ äë˙ ęëčĺíňŕ: ");
  85. gets(message);
  86. buffer = &message;
  87. WriteFile(hNamePipe, buffer, read_buffer, &actual_read, NULL);
  88. }
  89. }
  90. else
  91. {
  92. printf("\nĘëčĺíň îňęëţ÷čëń˙ îň ńĺđâĺđŕ");
  93. }
  94. CloseHandle(hNamePipe);
  95. }
  96. }