简体   繁体   English

Netcat作为UDP客户端不接收来自Arduino Wifi Shield的响应数据包。 简单的C UDP客户端。 为什么?

[英]Netcat as UDP Client does not receive response packets from Arduino Wifi Shield. Simple C UDP Client Does. Why?

I am testing out the WiFi UDP Send and Receive String example Arduino code with the Arduino Wifi Shield (newest firmware update Mar. 2013), and I'm getting behaviour I cannot explain. 我正在测试带有Arduino Wifi Shield的WiFi UDP发送和接收字符串示例Arduino代码(最新的固件更新于2013年3月),我得到的行为我无法解释。

Expected Operation 预期的运作

The Arduino receives UDP packets on its own local arbitrary port from another computer on the router - remoteIP:remotePort. Arduino从路由器上另一台计算机的本地任意端口接收UDP数据包 - remoteIP:remotePort。 It acknowledges to the client that it has received the packet by sending a UDP packet of its own back to remoteIP:remotePort. 它向客户端确认它已经通过将自己的UDP数据包发送回remoteIP:remotePort来接收数据包。

I thought I would test by using netcat. 我以为我会用netcat测试一下。 netcat will send the UDP packets and Arduino receives, but netcat is not receiving the packets sent by Arduino. netcat将发送UDP数据包并且Arduino接收,但netcat没有收到Arduino发送的数据包。 The blame lies in netcat, because I used a Simple C UDP Client and that client WOULD receive the Arduino server UDP responses. 责任在于netcat,因为我使用了简单的C UDP客户端 ,而客户端WOULD收到了Arduino服务器的UDP响应。

Does anyone know what extra cruft is in Netcat that would be causing this? 有谁知道Netcat会引起什么额外的瑕疵? I've noticed similar issues when using netcat on TCP to interact with servers using unknown protocols. 我在TCP上使用netcat与使用未知协议的服务器进行交互时发现了类似的问题。 The interaction was not "raw," things were not showing up that seemingly should be, like these UDP packets from the UDP server. 交互不是“原始的”,似乎应该没有出现的东西,就像来自UDP服务器的UDP数据包一样。 Is it something about the makeup of the UDP packets that does not satisfy netcat? 这是不是满足netcat的UDP数据包的构成?

Arduino UDP Server Code Arduino UDP服务器代码

Simple C UDP Client Code 简单的C UDP客户端代码

The main difference between your code and nc is, that you use an unconnected socket and specify the recipient within the sendto call, while nc will use a connected socket. 您的代码和nc之间的主要区别在于,您使用未连接的套接字并在sendto调用中指定收件人,而nc将使用连接的套接字。 This means, that your socket will accept replies from any address, while nc will only accept replies from the same IP and port where it send the request to. 这意味着,您的套接字将接受来自任何地址的回复,而nc将仅接受来自发送请求的相同IP 和端口的回复。 I don't know about the Arduino udp library you use, but from a short look at the code I don't see anything like using a udp connection, so I assume that my theory is correct. 我不知道你使用的Arduino udp库,但从简短的代码看我没有看到任何像使用udp连接,所以我认为我的理论是正确的。 If you use tcpdump/wireshark this is what I expect you to see with your client at IP cip and port cport and Arduino at IP cip and port 32000 (matching your example C-code): 如果您使用tcpdump / wireshark,我希望您在IP cip和端口cport以及Aripino的IP cip和端口32000(与您的示例C代码匹配)中看到您的客户端:

--> request from cip:cport to   aip:32000
<-- reply to     cip:cport from aip:random_port

But what you need if you want it to work with nc is 但是如果你想让它与nc一起使用你需要的是

--> request from cip:cport to   aip:32000
<-- reply to     cip:cport from aip:32000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM