Ok, I think at least I got something with socat
- namely, the option fork
needs to be appended to the server line:
$ socat - udp4-listen:5000,reuseaddr,fork
... and then, in another terminal, we can call echo
piping into socat
client line multiple times on command line, as it will exit immediately (well, after half a second :)):
$ echo "hello" | socat - udp-sendto:127.0.0.1:5000
$ echo "hello" | socat - udp-sendto:127.0.0.1:5000
$ echo "hello" | socat - udp-sendto:127.0.0.1:5000
... and going back to the first terminal, we can see that the server has successfully shown all three hello
s:
$ socat - udp4-listen:5000,reuseaddr,fork
hello
hello
hello
^C
Note that even with a fork
-ed socat
server, the line echo "hello" | nc -u 127.0.0.1 5000
will still 'lock' as if waiting for user input; however, now after Ctrl-C and re-running the command, i.e.
$ echo "hello" | nc -u 127.0.0.1 5000
^C
$ echo "hello" | nc -u 127.0.0.1 5000
^C
$ echo "hello" | nc -u 127.0.0.1 5000
^C
... the fork
-ed socat
server will show three hello
s without the need to be restarted..
Seemingly, this openBSD netcat
doesn't have a fork
option - but I'm not sure if it has one that is corresponding to it..
Anyways, hope this helps someone,
Cheers!
This comes straight from the Wikipedia page on netcat. In Term3, you would run:
mkfifo backpipe
nc localhost 55545 0<backpipe | nc localhost 55546 1>backpipe
This does pretty much exactly what you want. It uses a FIFO to get output from the left-hand side back into the right-hand side. It's not, strictly speaking, a temporary file -- a FIFO is a named pipe between two processes.
Best Answer
The answer is very simple at the end. We have to use
open('/dev/ptmx')
instead of oldopenpty()
mechanism.