Thank you both very much for your responses, as it turns out I was looking at this wrong, the actual problem was that the http server was closing the connection after serving a single request, which is why netcat was exiting.
I was just testing with busybox httpd, which doesn't support http keep-alive (but I actually knew that, so I have no excuse really...).
Testing with lighttpd and adding the "Connection: keep-alive" header, it just works exactly as I wanted.
szatox wrote:If you want to have many sources use a single netcat client, you can have it read from a fifo. Fifo terminates when the last program on either end exits, and it can be used by many programs at the same time. This means, you can use some idling process to keep the fifo open (say '( read; ) > fifo' ) and then you can even write with echo >fifo and it will not terminate connection even though it exits instantly.
Yeah, what I was doing was opening a file descriptor to the named pipes I had redirected netcat's stdin and stdout to in the shell script.
Still, even though sharing a single connection is possible, I'd rather go with one instance of nc/curl/anything per task.
Generally, I completely agree on this, but there are always exceptions.
Anyways, ty both again.