AsyncUdpSocket CFSocketSetAddress listen failure: 102

    currentIp = [MD5 currentIP];
    NSLog(@"currentIp:%@",currentIp);
    _udpSocket = [[AsyncUdpSocket alloc]initWithDelegate:self];
    NSError* error;

    [_udpSocket enableBroadcast:YES error:&error];
    [_udpSocket bindToAddress:currentIp port:48899 error:&error];//currentIP:192.168.1.100


    NSString* data = @"HF-A11ASSISTHREAD";
    [_udpSocket sendData:[data dataUsingEncoding:NSUTF8StringEncoding]
                  toHost:[self get255IpWithString:currentIp] // host:192.168.1.255
                    port:48899
             withTimeout:-1
                     tag:0];

    [_udpSocket receiveWithTimeout:-1 tag:156];


ios version: 9.1

sdk version :9.1


(nslog)

2015-11-05 14:01:10.415 ZZFColorLife[1335:573131] currentIp:192.168.1.100

2015-11-05 14:01:10.415 ZZFColorLife[1335:573131] CFSocketSetAddress listen failure: 102


Could anyone tell me why that problem show up and how to fix it?


To start, your error handling code is worrying. Consider this:

NSError* error; 

[_udpSocket enableBroadcast:YES error:&error]; 
[_udpSocket bindToAddress:currentIp port:48899 error:&error];//currentIP:192.168.1.100

Cocoa conventions are that you shouldn’t look at

error
unless you’ve looked at the method result to confirm that there was actually an error. I don’t know if AsyncUdpSocket follows those conventions but, if it does, then your code is definitely broken.

I’ve seen situations where such brokenness can cause ‘phantom’ errors, that is, there was an error internal to the call but that error wasn’t significant so the call actually succeeded even though

error
ends up being set. Again, I don’t know if that applies in this case, but I think it would make sense for you to fix your code before going further.

Error 102 is

EOPNOTSUPP
, which could be coming back for a variety of reasons. Internally
CFSocketSetAddress
calls
bind
, where the man page lists a potential cause of socket is not of a type that can be bound to an address. I’m not sure if tha’s the real reason as to what’s going on here, but it’s a place to start.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Running in a simulator?

AsyncUdpSocket CFSocketSetAddress listen failure: 102
 
 
Q