title: How to avoid netcat from blocking, when using it as a client to send a file or pipelining output?
body: <p>When I use netcat to talk to a server listening at a TCP socket using an input file or pipelining, the client then hangs and I cant send any input. Any idea how can I make it <strong>not block?</strong>
  At the of this question there's the code of the 'server' I'm using for this, it runs on PHP.</p>
  
  <p>If I do from terminal this:</p>
  
  <pre><code>netcat 192.168.1.10 3320
  </code></pre>
  
  <p>Then I can talk to the server undefinetely, it just echoes back every line I send (LF). </p>
  
  <p>But If I do this:</p>
  
  <pre><code>netcat 192.168.1.10 3320 &lt; file
  or
  echo "Something" | netcat 192.168.1.10 3320 
  </code></pre>
  
  <p>Then the server returns the contents of the file, but I can't communicate anymore with netcat. The [client] process just blocks.  Once the server is shutdown, then the client unblocks and everything written on console after the line above is interpreted by shell. </p>
  
  <p>I have been looking for an answer with no success, but from what I have read, this is an issue with netcat. It appears to treat the connection as closed once it sees an EOF. </p>
  
  <p>I have attempted the waiting option and keeps blocking:</p>
  
  <pre><code>netcat -q -1 192.168.1.10 3320 &lt; file
  </code></pre>
  
  <p>No success.
  What I am attemting to do is to do is to send the content of a file with netcat and then be able to send messages using the same console.</p>
  
  <p>The 'server':</p>
  
  <pre><code>&lt;?php
  
  set_time_limit(0);
  $address = "192.168.1.10";
  $port = 3320;
  $server_users = 3; 
  $mysock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n");
  $bind_result = socket_bind($mysock,$address, $port) or die("Could not bind to address\n"); 
  $listen_result = socket_listen($mysock, $server_users)  or die("Could not set up socket listener\n");
  $client = socket_accept($mysock) or die("Could not accept the connection to socket\n");
  
  do {
      $input = socket_read($client,1024,PHP_BINARY_READ);
      echo $input;
  } while(TRUE);
  ?&gt;
  </code></pre>
  
  <p>If you need to now, I run it in terminal using:</p>
  
  <pre><code>$ php -q server.php
  </code></pre>