Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8904237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:04:39+00:00 2026-06-15T02:04:39+00:00

I have tested this code on an iPad: // execute the function when press

  • 0

I have tested this code on an 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];

}

Please see the comments in the code above.

When I disconnect the Wifi connecttohost return yes. I don’t know where the problem is. Could anyone help me and give me some pointers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:04:40+00:00Added an answer on June 15, 2026 at 2:04 am

    For some reason connectToHost will always return true in this case. You need to rely on the delegate methods.

    - (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port {
        NSLog(@"Connected To %@:%i.", host, port);
    }
    
    - (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err {
        NSLog(@"Disconnecting. Error: %@", [err localizedDescription]);
    }
    
    - (void)onSocketDidDisconnect:(AsyncSocket *)sock {
        NSLog(@"Disconnected.");
    
        [socket setDelegate:nil];
        [socket release];
        socket = nil;
    }
    
    - (BOOL)onSocketWillConnect:(AsyncSocket *)sock {
        NSLog(@"onSocketWillConnect:");
        return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have xampp. I tested this code on ZendServer, result the same. <?php
I have tested this servlet and it works well, except in Google Chrome it
I have written this regexp: <(a*)\b[^>]*>.*?</\1> and is tested on this regexp testing site:
I need to open a URL link in another tab. I have tested this
I have this code: UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@OK otherButtonTitles:nil];
I have tested this in IIS 6.1, IE 7, ASP.NET 3.5 SP1. I have
I have used this code to open whatismyipaddress.com $fp = fsockopen(whatismyipaddress.com, 80, $errno, $errstr,
So I tested this code (intersection between two ellipses, look at the accepted answer),
I have a DetailViewController , which implementation file contains this code: #import <UIKit/UIKit.h> @interface
In my current company, we have one tester. Having spoken to this tester, she

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.