1

I'd like to use a file as a temporary buffer to connect two netcat processes. I need to use a buffer because data is sent and requested on each end at different intervals. I want to use a file instead of an actual mkfifo buffer because the data will often exceed 64 kb.

This is what I have, but it doesn't work. The file is never written to, or at least, it's not written to in a way that the publisher process can read it.

# receiver
while true; do nc -l 8000 > /tmp/my_file; done

# publisher
while true; do nc -l 9000 < /tmp/my_file; done

I send text to the receiver like this:

echo "hello, world" | nc localhost 8000

And I try to read it from the publisher like this:

curl localhost:9000

But curl returns an error like "empty reply from server" because "hello, world" has never been written.

I'm testing this in Mac OS but eventually need to do the same in Linux (Alpine, most likely).

skyler
  • 465
  • 3
  • 8
  • 17

1 Answers1

1

On some systems the "nc" command requires that you specify the "-p" option before the port number. Try to add a "-p" before 8000 and 9000 as follows:

# receiver
while true; do nc -l -p 8000 > /tmp/my_file; done

# publisher
while true; do nc -l -p 9000 < /tmp/my_file; done