1

I have a situation where many "smart" devices are sending me data via UDP. I can't change anything on the sending end.

I'm testing nc (or netcat) but can't get past the following:

Receiving end command:

nc -l -u 8123

Test sending command:

echo "test" | nc -u 127.0.0.1 8123

The first packet works fine, but then both ends seem to go to some sort of sleep and I have to CTRL+C to try again. Once it works I will have the receiving end "keep listening" (-k) and I will process the packets then

1

The answer, it if comes up - there's apparently some issue with netcat when used like this - socat provided a solution:

Receive:

socat -u udp4-recv:8123 - 

Send:

echo "test" | socat - udp4-sendto:127.0.0.1:8123
1

server side: nc -ul 127.0.0.1 1234 - listen to udp connection on port 1234

also: nc -l 1234

client side: nc -u 127.0.0.1 1234 - connect using udp to 127.0.0.1, port 1234

Now type something on the client side and you see it on the server side. (You can also type on the server side, and it will get through to the client.)

When you do echo "test" | nc -u 127.0.0.1 8123, the server side stays as before, but now the standard input of nc on the client side is bound to the pipe descriptor. When you type on the keyboard, it goes nowhere. nc is waiting for input from the pipe, and the pipe has already sent all it had to send. So now nc is "frozen".

1

According to the man page, you need to pass the -q0 flag to nc to make it exit when finished.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.