I want to use netcat as a TCP-server that reads data from a named pipe. For that I did the following:
Step 1. Created a pipe and the server that uses it as a source
mkfifo /tmp/all.pipe
nc -k -l 8080 < /tmp/all.pipe
Step 2. Created a client that reads the data continuously:
while true; do
sleep 1;
echo "Check connection";
while IFS= read -r line; do
printf "$line";
done < /dev/tcp/localhost/8080;
done
Step 3. Write some data to the pipe:
echo "hello" > /tmp/all.pipe
After execution of these 3 steps the output on the client side was:
...
bash: connect: Connection refused
bash: /dev/tcp/localhost/8080: Connection refused
Check connection
bash: connect: Connection refused
bash: /dev/tcp/localhost/8080: Connection refused
Check connection
hello
However when I executed the step 3 after this again, the output didn't change. Looks like it happened because the connection was still active, but the new data wasn't passed from the pipe to the nc and then to the client. Why? What can be done to achieve it?