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.
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.
Another netcat-like tool is the nmap version,
ncat
, that has lots of built in goodies to simplify things like this. This would work:-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
I used
socat -v PIPE udp-recvfrom:5553,fork
to run the server andsocat - udp:localhost:5553
for clients. This was a great help!You can also use socat (rather than using netcat) as echo server and netcat as client.
Socat echo server (listens on TCP port 1234):
Netcat client (connects to serverip on TCP port 1234):
You can write a C program that forks
nc -u -l -p 4321
and then uses dup(2) to connect:Then in an endless loop the parent reads from stdin and writes in stdout whatever the parent reads.
netcat
solution pre-installed in UbunutuThe
netcat
pre-installed in Ubuntu 16.04 comes fromnetcat-openbsd
, and has no-c
option, but the manual gives a solution:Then client example:
TODO: how to modify the input string value? The following does not return any reply:
The remote shell example however works:
I don't know how to deal with concurrent requests simply however.
If you are running on Windows and use a unix like environment like cygwin, netcat migth not provide the -e parameter. This worked just fine for me.
http://bansky.net/echotool/