iOS-Geräte empfangen kein UDP-Multicast mit GDAsyncUdpSocket

Der folgende Code soll UDP-Multicast-Nachrichten unter 239.255.255.250 empfangen und einfach den Inhalt der Nachricht mit NSLog protokollieren.

Wenn ich eine Nachricht an die IP des iOS-Geräts adressiere (d. H. Von einem Terminal aus)echo foo | nc -u 10.1.10.249 1900) Die Nachricht wird empfangen und NSLogged.

Wenn ich jedoch eine Nachricht an die Multicast-Adresse sende (echo bar | nc -u 239.255.255.250 1900) wird die Nachricht nicht empfangen.

Beim Start werden keine Fehlermeldungen protokolliert.

Gedanken darüber, wo ich schief gehe?

#import "ViewController.h"
#import "GCDAsyncUdpSocket.h"

@interface ViewController () {
    GCDAsyncUdpSocket *udpSocket;
}
@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];
    udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];

    NSError *error = nil;

    if (![udpSocket bindToPort:1900 error:&error]) {
        NSLog(@"Error starting server (bind): %@", error.description );
        return;
    }

    if(![udpSocket joinMulticastGroup:@"239.255.255.250" error:&error] ) { //]onInterface:@"en0" error:&error]) {
        NSLog(@"Error joining multicast group: %@",error.description);
        return;
    }

    if (![udpSocket beginReceiving:&error]) {
        [udpSocket close];
        NSLog(@"Error starting server (recv): %@", error.description);
        return;
    }

    NSLog(@"Udp server started on port %@:%hu", [udpSocket localHost_IPv4], [udpSocket localPort]);
}

- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data fromAddress:(NSData *)address withFilterContext:(id)filterContext {
    NSString *msg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"message rec'd: %@:%hu %@\n", [udpSocket localHost_IPv4], [udpSocket localPort],msg);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end

Antworten auf die Frage(1)

Ihre Antwort auf die Frage