我正在使用 asyncsocket 创建与目标 C 的套接字连接。我使用“connectToHost”方法执行此操作。我正在尝试处理套接字连接失败的情况。“connectToHost”应该在连接成功时返回“YES”,否则返回 NO。出于某种原因,它总是返回“是”。我什至提供了一个空白字符串作为主机,它仍然返回是。有什么想法吗?
谢谢,
罗宾
BOOL connectStatus = NO; //used to check if connection attempt succeeded
testSocket = [[AsyncSocket alloc] initWithDelegate: self];
connectStatus = [testSocket connectToHost: @"" onPort: 5000 error: nil];
if(connectStatus == NO)
{
NSLog(@"Failed to connect to socket ");
}
else {
NSLog(@"Connected to socket sucessfully, connectStatus = %d", connectStatus);
}