让 netcat 监听多个 UDP 数据包

Ale*_*int 8 netcat

如果我像这样运行一个简单的 UDP 侦听器:

nc -l -u -p 1234
Run Code Online (Sandbox Code Playgroud)

然后我似乎只得到第一个入站 UDP 数据包。例如,如果我运行:

$ echo abc | nc -u localhost 1234
  ["abc" appears in output of server as expected]

$ echo abc | nc -u localhost 1234
read(net): Connection refused
Run Code Online (Sandbox Code Playgroud)

小智 9

使用零 (0) 超时

“服务器”:

nc -kluvw 0 localhost 9000
Run Code Online (Sandbox Code Playgroud)

“客户”:

echo -e "all"     | nc -vuw 0 localhost 9000
echo -e "the"     | nc -vuw 0 localhost 9000
echo -e "udp"     | nc -vuw 0 localhost 9000
echo -e "packets" | nc -vuw 0 localhost 9000
Run Code Online (Sandbox Code Playgroud)

结果:

Connection from 127.0.0.1 port 9000 [udp/*] accepted
all
Connection from 127.0.0.1 port 9000 [udp/*] accepted
the
Connection from 127.0.0.1 port 9000 [udp/*] accepted
udp
Connection from 127.0.0.1 port 9000 [udp/*] accepted
packets
Run Code Online (Sandbox Code Playgroud)

测试:

uname -a
Linux ubuntu 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Linux
Run Code Online (Sandbox Code Playgroud)