GCDAsyncUdpSocket on iOS missing multicasted datagrams

我怕爱的太早我们不能终老 提交于 2019-11-30 04:03:18

Through my work on networking apps for iOS devices I have revealed that their network adapters have two different modes, let's call them active and passive. I did not manage to find any documentation on this. Here are my findings:

  1. As long as in active mode, the adapter is quite responsive. I have response times of 3-5ms.

  2. After some time of inactivity, the network adapter of the iOS falls from active to passive mode. The time for this to happen, depends on the actual device model. 3rd gen iPad it is around 200ms. For the iPhone 4 its more like 50ms.

  3. A ping request or a TCP packet will move the adapter from passive to active mode. This may take anything from 50ms to 800ms, with an average of around 200ms.

This behavior is completely reproducible by issuing ping commands. E.g.

ping -i 0.2 <ios-device-ip>

sets the ping interval to 200ms and keeps my iPads network adapter in the active state.

This behavior is completely consistent with your observations, if the adapter (more often than not) ignores UDP packets when in passive mode. The wireshark activity probably keeps it in active mode so then it would get the UDPs.

Check out whether the ping trick helps.

One probably could keep the network adapter of the iDevice in the active state by opening and connecting two sockets on the device itself and regularly sending itself packets. This would introduce some minimal overhead.

As to why apple decided to implement such a feature, I can only speculate about. But probably keeping the adapter active costs sufficient battery power to legitimate such a design choice.

Hope this helps.

I had the same issue.

Starting the network activity indicator solved that problem for me:

UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;

If you want to view the packet on the iOS device, you can tether your iOS device to a Mac and mount the wifi adapter using shell command rvictl. You can then use wireshark, tcpdump, etc. to monitor the traffic on your 802.11 interface on your iOS device.

As far as not receiving data until 3 to 7 seconds - Most likely your device is entering into power save mode (IEEE PSM) which is an 802.11 feature that essentially puts the wireless NIC to sleep.
PSM mode can yield poor performance on devices - especially in your case where you have periodic bursts of data every 1/2 second. Your periodic ping is waking the NIC up.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!