title: GCDAsyncUdpSocket on iOS missing multicasted datagrams
body: <p>I have a device on the network that is multicasting a very small file via UDP. The iOS app I am developing is responsible for reading these packets and I have chosen to use <a href="https://github.com/robbiehanson/CocoaAsyncSocket" rel="noreferrer">GCDAsyncUdpSocket</a> to do so. The file is sent every half second, however I am not receiving it nearly that often (only receiving about every 3-10 seconds). </p>
  
  <p>Thinking that it may be an issue with the device, I began monitoring the traffic with Wireshark. This appeared to reflect what I was seeing in my app until I enabled "Monitor Mode" in Wireshark, at which point every UDP packet was being captured. In addition, the iOS simulator began receiving all of the missing packets since it shares the NIC with the Mac I am developing on.</p>
  
  <p>Is there a way to enable "Monitor Mode" on an iOS device or something I am missing that would allow the missing packets to come in? I also see that there is a readStream method in GCDAsyncUdpSocket. Perhaps I need to use this instead of beginReceiving? Though I do not know how to set up streams in Objective-C if that is the case.</p>
  
  <p>Here is my test code as it is now: </p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
      NSLog(@"View Loaded");
      [self setupSocket];             
  }
  
  - (void)setupSocket
  {
      udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
      NSError *error = nil;
      if (![udpSocket bindToPort:5555 error:&amp;error])
      {
          NSLog(@"Error binding to port: %@", error);
          return;
      }
      if(![udpSocket joinMulticastGroup:@"226.1.1.1" error:&amp;error]){
          NSLog(@"Error connecting to multicast group: %@", error);
          return;
      }
      if (![udpSocket beginReceiving:&amp;error])
      {
          NSLog(@"Error receiving: %@", error);
          return;
      }
      NSLog(@"Socket Ready");
  }
  
  - (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data
        fromAddress:(NSData *)address
  withFilterContext:(id)filterContext
  {
      NSString *msg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
      if (msg)
      {
          NSLog(@"RCV: %@", msg);
      }
      else
      {
          NSString *host = nil;
          uint16_t port = 0;
          [GCDAsyncUdpSocket getHost:&amp;host port:&amp;port fromAddress:address];
          NSLog(@"Unknown message from : %@:%hu", host, port);
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Solution for anybody who comes looking here in the future:</strong></p>
  
  <p>Based on ilmiacs's answer, I was able to significantly reduce the number of missing packets by pinging the target iOS device. Using a Mac, I ran this in the terminal - </p>
  
  <pre><code>sudo ping -i 0.2 -s 4 &lt;Target IP&gt;
  </code></pre>
  
  <p>Now that I have it running with a Mac pinging the iOS device, I am going to look into Apple's iOS ping examples and see if I can have the device ping itself to stimulate its own wireless adapter (127.0.0.1).</p>