title: read from a named pipe
body: <p>I have to implement a "printing server". I have 1 client file, and 1 server file:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  
  int get_line( char *dest, int size );
  
  #define MAX 1024
  
  void main ()
  {
      char const *pipe = "printservers";
      char buffer[MAX];
      int fd;
  
      get_line( buffer, MAX );
  
      if( mkfifo( pipe, 0666 ) &lt; 0 )
      {
          printf( "Cannot create a pipe\n" );
          exit( EXIT_FAILURE );
      }
  
      fd = open( pipe, O_WRONLY );
  
      write( fd, buffer, MAX );
  
      close( fd );
  
      //unlink( pipe );
  
  }
  
  int get_line( char *dest, int size )
  {
      int c, i;
      for( i = 0; i &lt; size - 1 &amp;&amp; ( c = getchar() ) != EOF &amp;&amp; c != '\n'; ++i )
          dest[i] = c;
      if( c == '\n' )
      {
          dest[i] = c;
          ++i;
      }
      dest[i] = '\0';
      return i;
  }
  </code></pre>
  
  <p>This is the client, which reads from the standard input a line and writes into a 
  named pipe called printservers. This works as intended.</p>
  
  <pre><code>#include &lt;fcntl.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;unistd.h&gt;
  
  #define MAX_BUF 1024
  #define MAX_PID 8
  
  int main()
  {
      int fd;
      char * myfifo = "printservers";
      char buf[MAX_BUF];
  
      /* open, read, and display the message from the FIFO */
      fd = open( myfifo, O_RDONLY );
      while( 1 )
      {
          if( read( fd, buf, MAX_BUF ) &gt; 0 )
              printf("Received: %s\n", buf);
      }
      close(fd);
  
      return 0;
  }
  </code></pre>
  
  <p>This is the server, which are read from the pipe. But it does not work with the while loop. If i send a message from the client, the first message is printed, but the following messages are ignored.
  Could somebody help me with my problem?
  Thanks
  Patrik</p>