How to make an Echo server with Bash?

If you use ncat instead of nc your command line works fine with multiple connections but (as you pointed out) without -p.

ncat -l 2000 -k -c 'xargs -n1 echo'

ncat is available at http://nmap.org/ncat/.

P.S. with the original the Hobbit's netcat (nc) the -c flag is not supported.

Update: -k (--keep-open) is now required to handle multiple connections.


Here are some examples. ncat simple services

TCP echo server

ncat -l 2000 --keep-open --exec "/bin/cat"

UDP echo server

ncat -l 2000 --keep-open --udp --exec "/bin/cat"