开发者

iPhone AsyncSocket always connecting on any port!

开发者 https://www.devze.com 2022-12-21 10:18 出处:网络
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?

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 mlu开发者_运维知识库Presenter[2083:207] Conectou! even if I change the port to 1 or to a port out of the range...

Thanks in advance.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消