我在 iPad 上测试了这段代码:
// execute the function when press button
- (IBAction)connect:(id)sender {
//[super viewDidLoad];
AsyncSocket *socket1=[[AsyncSocket alloc] initWithDelegate:self];
BOOL pass = [socket1 connectToHost:@"www.126.com" onPort:80 error:nil]; // but when I break the wifi,connecttohost still return yes
if(pass)
{
[connectbtn setTitle:@"connected" forState:UIControlStateNormal];
}
[socket1 readDataWithTimeout:3 tag:1];
[socket1 writeData:[@"GET / HTTP/1.1\n\n" dataUsingEncoding:NSUTF8StringEncoding] withTimeout:3 tag:1];
}
请参阅上面代码中的注释。
当我断开 Wificonnecttohost
时返回yes
。我不知道问题出在哪里。任何人都可以帮助我并给我一些指示吗?