Combine netcat with chat on bash for udp auto response

I want to combine "chat" and "nc" in linux, so I will create a tiny udp server that answers a specific request and sends a response.

Actually, I want to redirect stdout "nc" to stdin "chat" and vice versa. My first attempt:

nc -w 3000 -u -n -l -p 30000 >&1111 <2222 & chat -V 'request' 'answer' >&2222 <1111 

But that did not work.

+2
source share
1 answer

use socat instead of netcat. Something like that:

 socat UDP-LISTEN:5555 EXEC:"chat -sv ping pong",pty 

To check this, you can open another terminal and use socat to connect stdio and UDP socket:

 socat - UDP:localhost:5555 

Enter ping and you will get pong!

+3
source

All Articles