udp socket not receiving some of the packets

Hi,

I've been using CocoaAsyncUdpSocket (IPv4) for UDP listening on my app, and it seems that some of the packets are not received (not in any consistent manner). All the UDP communication is done through LAN (WiFi), so I assumed all the packets should arrive safely...



I've tried tracking down the issue, and I found that "MyCFSocketCallback" in AsyncUdpSocket.m wasn't called when a packet was dropped. (so it's not a high-level problem)



I've recently transferred all the code from obj-c to swift, and have updated my devices to iOS 9, so I have a feeling that this issue has something to do with that.

I thought this may be due to the requirement of using IPv6 in iOS 9, so I've attempted changing my sockets to IPv6, which seemed to have caused an improvement (although it could be random, or wishful thinking :)). Unfortunately, I'm still seeing packet drops, which is somewhat problematic...



Any help or direction would be highly appreciated, as I tried looking around for similar issues, but I didn't manage to find anything...



Thank you!

All the UDP communication is done through LAN (WiFi), so I assumed all the packets should arrive safely...

Just FYI, that’s not a valid assumption. Every time you use UDP you have to deal with the fact that packets might be lost. Packet loss is relatively rare on the local WLAN, but it does happen and your product must be able to cope.

Anyway, if you really want to get to the bottom of where the packets got dropped, you can use the technique I described in this post (on the old DevForums) to trace the packet’s progress through every step in its travels. It’s a lot of work in the general case, but you can probably take some shortcuts. For example, a packet trace on the receiving device would let you see whether the receiving device ever received the packet.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo,

Thank you very much for the quick response! 🙂


I know packets may be lost, but when I previously used the same method, on the same device, in obj-c (iOS 7 I think), it worked fine. So I assumed that random UDP packet loss isn't the issue (if I lose a few packets out of many, it's not a big threat), but I currently lose about 30% of packets.


The link you gave me doesn't seem to lead anywhere... can you provide me with a quote or an image? (or another link possibly?)

How can I perform packet tracing on the receiving device? That would be a great way to see where the problem lies! 🙂


I've previously tried packet sniffing the LAN, and I saw all the packets were being sent properly - including the ones which aren't received.

I've also put two iPads - side by side - with the old and new versions, and the old one received all packets, while the new one missed some.


This seems like a very weird issue, and I'm a bit lost for a solution... So any help is greatly appreciated!


Thank you very much for your assistance!

Tamper

Hi,

I've managed to find a few posts that explain how to trace packets on a target device:

http://useyourloaf.com/blog/remote-packet-capture-for-ios-devices/

https://developer.apple.com/library/ios/qa/qa1176/_index.html#//apple_ref/doc/uid/DTS10001707-CH1-SECRVI


I've downloaded wireshark onto my Mac, set my iPad as a remote virtual interface, and started recording the remote virtual interface's packets. I saw that whenever a packet was not received in the app, it was not shown in wireshark - a.k.a, it didn't even reach the device, and was dropped prior to that. (or that I'm missing something)

At the same time I ran wireshark on another computer connected to the same LAN which showed me all the packets (as they're all broadcast packets, set to 10.0.0.255), with 0% loss .


I'm rather confused as to why the packets all seem to be arriving to my other computers safely, but not to my target device... my current suspecions are:

  1. Something to do with it being a broadcast packet.
  2. Something to do with iOS 9's difference in networking (IPv6 vs IPv4 maybe?)


Any help would be greatly appreciated! 🙂

Thanks,

Tamper


EDIT: I've tried sending unicast messages instead of broadcast messages, and it seems like there is no packet loss! So the problem has something to do with broadcast... My current solution requires sending data to multiple clients, so I can't use unicast (unless I send to many clients individually...), so if possible, I would rather stay with broadcast (or maybe multicast?).


EDIT2: I've tried using multicast now, and it seems to ALSO be working properly!! It seems like this problem is only with broadcast messages...

I think it may be possible for me to change the system to work with multicast addresses, but I would still like to get to the bottom of the issue - to make sure it won't return later in a different environment.

The link you gave me doesn’t seem to lead anywhere

Indeed. It seems that old DevForums is having a bad day :-(JSYK, the link worked when I posted it).

I’ve tidied up the text a little and posted it here.

1. Something to do with it being a broadcast packet.

Ah, this is the first time you’ve mentioned broadcasts. Broadcasts on Wi-Fi are troublesome. I’ve explained this in various posts in the past, but rather than point you to some specific post I’ve written up a more general explanation, which you can find here.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = “eskimo” + “1” + “@apple.com”
udp socket not receiving some of the packets
 
 
Q