title: Windows Inter Process Communication (IPC) (named pipe) - slave program doesn't receive any data since a random time
body: <p>I had a host program (A) and a slave program (B),
  A sends some data (as a command) to B periodically (approximately per 0.5 sec.), while B receives the command form A, it does something corresponding.</p>
  
  <p>Everything goes right in the beginning, but after a while, maybe 3 mins or 5 mins later, <strong>at a random time, B doesn't receive new command anymore,</strong> but A is still sending new commands.</p>
  
  <p>I check the state of both A &amp; B by writing some text log, the logs look like the following:</p>
  
  <p>&lt;&lt; What A sent >>
  Command 1
  Command 2
  Command 3
  ...
  Command 70
  ...
  Command 100</p>
  
  <p>&lt;&lt; What B received >>
  Command 1
  Command 2
  Command 3
  ...
  Command 70 (just stop here, 71 ~ 100 is missing)</p>
  
  <hr>
  
  <p>The core part of the Host program (A):</p>
  
  <pre><code>...
  HANDLE host_to_slave;
  DWORD host_to_slave_buffer_index;
  ...
  
  for(int i = 0; i &lt; 1000; i++)
  {
      ...
      std::string temp_string = "S/1.234567/9.876543"/";
      const char *command_str = temp_string.c_str();
      WriteFile(host_to_slave,
          command_str,
          temp_string.length(),
          &amp;host_to_slave_buffer_index,
          NULL);
      Sleep(300); // Wait for some hardware.
  
      // Here write temp_string (command sent to B) to the log file.
      ...
  }
  ...
  </code></pre>
  
  <hr>
  
  <p>The core part of the slave program (B):</p>
  
  <pre><code>...
  HANDLE host_to_slave;
  char host_to_slave_buffer[1024];
  DWORD host_to_slave_buffer_index;
  ...
  
  while(true) // Infinite checking loop
  {
      ...
      ReadFile(host_to_slave,
          host_to_slave_buffer,
          sizeof(host_to_slave_buffer) - 1,
          &amp;host_to_slave_buffer_index,
          NULL);
      host_to_slave_buffer[host_to_slave_buffer_index] = '\0';
  
      if (host_to_slave_buffer[0] != '\0')
      {
          ...
          // Here write host_to_slave_buffer[] (command from A) to the log file.
          ...
      }
      ...
      Sleep(10); // The minimum period of infinite checking loop.
  }
  </code></pre>
  
  <p>B just check if there is any new command from A forever and does something corresponding. I just cannot figure out why it does not receive any command since a "random" time. For example, something the log of B gets stuck at Command 70, sometimes, Command 30, Command 90. But the log of A always behaves as expected - keep sending command until the latest command, is there anything to do with the Windows os?</p>