title: Reading continuous data from a named pipe
body: <p>I have been trying to read continuous data from a named pipe. But for some reason if I don't put a delay, the receiver will just stop reading and only a blank screen is shown after a few samples. </p>
  
  <p>I need to send continuous data that might change in milliseconds, so that's why putting a delay wouldn't work. I am trying to simulate it first using a while loop (the real script will be reading financial data). This is my first attempt:</p>
  
  <p>This is the sender, a python script:</p>
  
  <pre><code>import os
  import time
  
  try:
      os.remove("/tmp/pipe7")    # delete
  except:
      print "Pipe already exists"
  os.mkfifo("/tmp/pipe7")    # Create pipe
  x = 0
  while True:
      x = time.time()
      pipe = open("/tmp/pipe7", "w")
      line = str(x) + "\r\n\0"
      pipe.write(line)
      pipe.close()
  
      #time.sleep(1)
  
  
  os.remove("/tmp/pipe7")    # delete
  </code></pre>
  
  <p>This is the receiver in C/C++:</p>
  
  <pre><code>#include &lt;fcntl.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;iostream&gt;
  
  #include &lt;sys/stat.h&gt;
  
  #define MAX_BUF 1024
  
  
  using namespace std;
  
  int main()
  {
  
      while(1){
  
          char buf[MAX_BUF];
          memset (buf, 0, sizeof(buf)); //Clearing the message buffer
          int fd = open("/tmp/pipe7", O_RDONLY);  // Open the pipe
          read(fd, buf, MAX_BUF);                         // Read the message - unblock the writing process
          cout &lt;&lt; buf &lt;&lt; endl;
          close(fd);                                 // Close the pipe
  
      }
      return 0;
  }
  </code></pre>
  
  <p>What's wrong with my approach? And what's the best way to communicate continuously between the two programs using pipes?</p>