0

Im working in an app where you suscribe to a multicast socket to listen to other devices that post to that socket. When listening everything is working fine. The problem is when I try to post to that socket in a local network. It says "Network unreachable" and I can't send the data. My code is like this.

PORT 5775
SOCKETADDRESS @"225.4.5.6"

Listener

self.socket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];

if (![self.socket bindToPort:PORT error:&error])
{
    NSLog(@"Error binding to port: %@", error);
    return;
}
if(![self.socket joinMulticastGroup:SOCKETADDRESS error:&error]){
//   NSLog(@"Error connecting to multicast group: %@", error);
   // return;
}
if (![self.socket beginReceiving:&error])
{
    NSLog(@"Error receiving: %@", error);
    return;
}

Client(Sender)

self.udpSender = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];

if (![self.udpSender bindToPort:BRD_PORT error:&error])
{
    NSLog(@"Error binding to port: %@", error);
    return;
}

if(![self.udpSender enableBroadcast:YES error:&error]){
  //  NSLog(@"broadcast s%@", error);
    //return;

}

And I try to write like this.

[self.udpSender sendData:input toHost:SOCKETADDRESS port:PORT withTimeout:-1 tag:0];

This codes work when I have internet access. But when I connect to a local network the sender says "Network is unreachable". I don't know what I'm doing wrong. Hope you can help me. Thanks.

Jlrodv
  • 1
  • To me this looks like it should be working fine offline. You don't have any `Reachability` code on application launch that could trigger this behaviour? – Mellson Feb 16 '15 at 13:38
  • @Mellson thank you. It was a weird configuration between iOS and the lan, like a bad password, I couldn't recreate it but restarted the network and it worked. – Jlrodv Feb 24 '15 at 00:35

0 Answers0