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.