CFSocketConnectToAddress 和无法识别的选择器发送到实例
我对 iPhone 开发有点陌生,当我在此代码中调用 CFSocketConnectToAddress 时,我一直遇到无法识别的选择器。我认为我做错了可能是一些基本的事情。有什么想法吗?
这是我得到的完整错误。
NSInvalidArgumentException 无法识别的选择器发送到实例 0x3922170
0x3922170 是调用类。
- (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;
}
无效套接字回调( CFSocketRef s, CFSocketCallBackType 回调类型, CFDataRef地址, 常量无效*数据, 无效*信息) {
}
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)
{
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误有点难以跟踪,因为 NSInvalidArgumentException 是该错误的奇怪错误消息。但问题是我还没有解析 NSNetService 并且地址数组为空。如果您使用空地址数组调用 CFSocketCreate,您将收到该错误。
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.