Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting to an invalid host does not fail #57

Closed
jan-ekholm opened this issue May 23, 2012 · 1 comment
Closed

Connecting to an invalid host does not fail #57

jan-ekholm opened this issue May 23, 2012 · 1 comment
Labels

Comments

@jan-ekholm
Copy link

I use GCDAsyncSocket to connect to an own TCP server of mine. I noticed that the socket never fails nor gives any error when the hostname is invalid and does not exist:

self.socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];

host = @"totallyinvalid";

NSError * error = nil;
if ( ! [self.socket connectToHost:host onPort:29927 withTimeout:10 error:&error] ) {
    NSLog( @"failed to connect" );
    return;
}
if ( error ) {
    NSLog( @"failed to connect: %@", [error localizedDescription] );
    return;
}

Nor are the timeout callbacks called, even when running for a long time. Any way to work around this? The hostnames I've tried with do not resolve to anything at all and even when trying with an invalid IP there is no error.

@krestenkrab
Copy link

You need to listen for the socketDidDisconnect:withError: delegate callback. The initial connectToHost:onPort: call just does some basic validation and initiates the connect, later you'll get the error callback mentioned before or socket:didConnectToHost:port: callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants