Reputation: 55
I’m new to Winsock programming, so apologies in advance if this is a “dumb” question.
I’ve written a Windows app which sends data via UDP to an external device. Since UDP is the only protocol supported by the external device, I am unable to use a more robust protocol such as TCP.
Now, if my program makes say 6 calls to WSASentTo in rapid succession, one of two things will happen:
If the previous message was sent recently, and the target device is still in Windows’ ARP cache, then all 6 messages are sent to the external device.
If however, the device is no longer in Windows’ ARP cache, then only one or two of the messages are sent. The others appear to vanish somewhere.
My app uses a different buffer every time it calls WSASendTo, so my app shouldn’t be overwriting it’s own data. I also think I have WSASendTo set up correctly for overlapped I/O. The messages are quite small (only about 50 data bytes each), so I can’t imagine I’d be overflowing a buffer anywhere. The “network” consists of just the PC and target device with a single cat5 cable linking the two.
While I could just add a regular “heartbeat” to keep the device in Windows’ ARP cache (and probably will), I’m still concerned that something isn’t working the way it should.
Any ideas?
Upvotes: 1
Views: 619
Reputation: 2450
Unfortunately, since UDP makes no guarantees about delivery, the network stack can drop your sent packets at any time for any reason, so it's impossible to classify this type of issue as not working as it should.
For your specific scenario, Microsoft has addressed this type of UDP drops during ARP resolution in the past. It is possible/likely the behavior remains in current implementations.
From ARP and UDP Messages
ARP queues only one outbound IP datagram for a given destination address while that IP address is being resolved to a MAC address. If a UDP-based application sends multiple IP datagrams to a single destination address without any pauses between them, some of the datagrams might be dropped if there is no ARP cache entry present. An application can compensate for this by calling the Iphlpapi.dll routine SendArp() to establish an arp cache entry, before sending the stream of packets. See the platform Software Development Kit (SDK) for additional information.
Upvotes: 1