CFSocketConnectToAddress 和无法识别的选择器发送到实例

发布于 2024-08-29 18:30:53 字数 963 浏览 2 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-09-05 18:30:53

该错误有点难以跟踪,因为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文