On a Ubuntu system I have the netcat(-openbsd) package installed, the one that, when run with no parameters, prints:
* If I omit the
This is nc from the netcat-openbsd package. An alternative nc is available
in the netcat-traditional package.
usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length]
[-P proxy_username] [-p source_port] [-q seconds] [-s source]
[-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]
[-x proxy_address[:port]] [destination] [port]
I run this command, which I think listens on a UDP port:
nc -v -u -l -k 1234
Then in another terminal I run this to talk to the listener:
nc -v -u 127.0.0.1 1234
But this behaves very different than I expect:
* When I run the second command (sender), the first one (listener) starts printing "X" characters, one per seconds, 5 times. Only then the sender reports a successful connection. (How does it even know with UDP?)

-v
parameter on the sender side, which I thought only sets the logging verbosity, then the "X" characters are not printed on the listener side and instead the connection is established immediately.
* Despite giving the -k
parameter on the listener side, once I make a connection to the listener, the listener seems to be "used up". If I kill (Ctrl+C) the sender and start it again, any data sent is lost (does not appear on the listener side).
What am I missing? How do I *correctly* listen on a UDP port?
**Edit:** I found a way that works well (socat -u UDP-RECV:1234 STDOUT
) but I'm keeping this question open because I'm still interested in an explanation.
Asked by AndreKR
(1218 rep)
Nov 12, 2024, 04:15 AM
Last activity: Nov 12, 2024, 08:14 AM
Last activity: Nov 12, 2024, 08:14 AM