views:

340

answers:

2

Hi there! I'm using (or trying to...) AsyncSocket to connect to a server but it always connect even if the server is not running... I'm using the SDK 3.1.2. Anyone faced this problem before?

#import "mluPresenterAppDelegate.h"
#import "AsyncSocket.h"

@implementation mluPresenterAppDelegate

@synthesize window;


#pragma mark -
#pragma mark Application lifecycle

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    AsyncSocket *assClient = [[AsyncSocket alloc] initWithDelegate:self];
    NSError *err = nil;
    if (![assClient connectToHost:@"127.0.0.1" onPort:7777 error:&err]) {
        NSLog(@"%@ %@", [err code], [err localizedDescription]);
    } else {
        NSLog(@"Conectou!");
    }
    [window makeKeyAndVisible];
}

The result is always 2010-02-22 22:54:26.922 mluPresenter[2083:207] Conectou! even if I change the port to 1 or to a port out of the range...

Thanks in advance.

+2  A: 

My memory is that it is not actually connected when -connectToHost:onPort:error: returns, it's just successful in making the attempt. A delegate method informs you when the connection has either succeeded or failed.

Ken
Thats right friend! Thanks a lot!
Paulo Ferreira
A: 

When successfully conneted to a given host and port, didConnectToHost:port delegate shoud fire.connectToHost:onPort:error: return just an indicator whether you can try on the socket.

charith