GCDAsyncUDPSocket: Not receiving any data though it is successfully sent
<p>I am trying to create a UDP socket and send data to a broadcasting port so that I can receive the same on other devices in the same WiFi network. I am calculating the IP address of broadcasting port as given in the accepted answer <a href="https://stackoverflow.com/questions/21077133/calculating-the-broadcast-address-in-objective-c">here</a>.</p>

<p>After that I have written some connection code which is as below:</p>

<pre><code>self.udpSocket = [[GCDAsyncUdpSocket alloc]initWithDelegate:self delegateQueue:dispatch_get_main_queue() socketQueue:nil];
NSError *error;
[self.udpSocket enableReusePort:YES error:&amp;error];
[self.udpSocket enableBroadcast:YES error:&amp;error];

- (IBAction)sendMessageToBroadcastPort:(id)sender {
 [self.udpSocket sendData:[@"Hi" dataUsingEncoding:NSUTF8StringEncoding] toHost:[self getUDPBroadcastAddress] port:5556 withTimeout:-1 tag:1];
}
</code></pre>

<p>I get success in sending the data as the delegate method didSendData: gets called.</p>

<p>Please guide me on what am I missing here.</p>

<p>Thanks!</p>

<p><strong>UPDATE:</strong>
Cpde for receiving the data from  the broadcasting port:</p>

<pre><code>- (void)listenForPackets
{
dispatch_queue_t dQueue = dispatch_queue_create("client udp socket", NULL);
udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dQueue socketQueue:nil];
NSError *error = nil;

if (![udpSocket bindToPort:5556 error:&amp;error]) {
    NSLog(@"Error binding: %@",error);//not connecting to host
    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>

<p>The broadcasting IP which I get after calculation is 192.168.2.255</p>

<p><strong>UPDATE 2:</strong>:</p>

<p>The scenario I am facing is really different and weird. The receiving works sometimes and sometimes it doesn't.
When I installed two apps there were no data received. Only sending was successful. I kept the apps on and after some time the app started receiving data. At some instances it stopped receiving after some time or kept receiving without any issue. What can be the issue?</p>