This is a simple echo server in Unix, using nc:
mkfifo fifo
cat fifo | nc -k -l 4458 -v | cat >fifo
(based on this)
As I can see it, the data flow works as follows:
fifo (my named pipe)
|
| (using cat)
|
v
nc
|
| (using cat)
|
v
fifo
And here is the question: why doesn't this work?
nc -k -l 4458 -v >fifo <fifo
You will notice that if you try to telnet
to localhost
on 4458
you will get a "Connection refused" error.
cat myfifo | nc -k -l 4458 > myfifo
also works. If you use a text file, file.txt like sonc -k -l 4458 < file.txt > file.txt
The first connection will connect and close (makes sense because the input was truncated and EOF closes the socket), the second connection will become a forgetful echo server: it will echo every other line and save the unechoed lines to the text file. – user1794469 May 19 '16 at 15:13