Echo server with netcat or socat

echoservernetcatsocat

I want a UDP echo server to get packets, and reply exactly what it has received. How can I simply do this using netcat or socat? It should stay alive forever and handle packets coming from several hosts.

Best Answer

Another netcat-like tool is the nmap version, ncat, that has lots of built in goodies to simplify things like this. This would work:

ncat -e /bin/cat -k -u -l 1235

-e means it executes /bin/cat (to echo back what you type)
-k means keep-alive, that it keeps listening after each connection
-u means udp
-l 1235 means that it listens on port 1235