views:

150

answers:

1

Hello, I am somewhat new to iPhone dev and I have been getting unrecognized selector when I call CFSocketConnectToAddress in this code. I think it might be something basic that I am doing wrong. Any idea?

this is the complete error I get.

NSInvalidArgumentException unrecognized selector sent to instance 0x3922170

0x3922170 is the calling class.

- (BOOL)connect

{ CFSocketRef mySocket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_DGRAM,IPPROTO_UDP, 0, socketCallback, NULL);

@try {
    CFDataRef data = (CFDataRef)[_netService addresses]; 
    CFSocketConnectToAddress(mySocket, data, 500);

}
@catch (NSException * e) {
    NSLog([e name]);
    NSLog([e reason]);
}


//char joke[] = "Why did the chicken cross the road?";
//CFSocketError err = CFSocketSendData(mySocket, joke, (strlen(joke)+1), 10);
return true;

}

void socketCallback ( CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info) {

}

A: 

The error was kind of hard to track because NSInvalidArgumentException is an odd error message for this error. But what went wrong was that I had not resolved the NSNetService yet and the addresses array was empty. If you call CFSocketCreate with an empty adress array you will get that error.

madmik3