通过Netcat发送UDP数据包到Memcached

通过Netcat发送UDP数据包到Memcached

我正在尝试stats通过 netcat 将命令发送到 memcached,但是,我没有从 memcached 得到任何返回...

我努力了

echo "stats" > commands.txt
nc -u 127.0.0.1 11211 < commands.txt

我也尝试过

echo stats | nc -u 127.0.0.1 11211

从我在底部读到的内容Memcached 文档,第 1176 行,发送的命令可能必须包括

Each UDP datagram contains a simple frame header, followed by data in the
same format as the TCP protocol described above. In the current
implementation, requests must be contained in a single UDP datagram, but
responses may span several datagrams. (The only common requests that would
span multiple datagrams are huge multi-key "get" requests and "set"
requests, both of which are more suitable to TCP transport for reliability
reasons anyway.)

The frame header is 8 bytes long, as follows (all values are 16-bit integers 
in network byte order, high byte first):

0-1 Request ID
2-3 Sequence number
4-5 Total number of datagrams in this message
6-7 Reserved for future use; must be 0

我的问题是,如何stats使用 netcat 通过 udp 将命令发送到 Memcached?

答案1

以下有效,您必须指定帧头

printf '\x00\x00\x00\x00\x00\x01\x00\x00stats\r\n' | nc -u 127.0.0.1 11211

相关内容