iPhone AsyncSocket 始终连接到任何端口!
我正在使用(或尝试...)AsyncSocket 连接到服务器,但即使服务器未运行它也始终会连接...我正在使用 SDK 3.1.2。以前有人遇到过这个问题吗?
#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];
}
结果始终是 2010-02-22 22:54:26.922 mluPresenter[2083:207] Conectou! 即使我将端口更改为 1 或更改为超出范围的端口...
谢谢进步。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的记忆是,当
-connectToHost:onPort:error:
返回时,它实际上并没有连接,它只是成功地进行了尝试。连接成功或失败时,委托方法会通知您。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.当成功连接到给定的主机和端口时, didConnectToHost:port delegate 应该 fire.connectToHost:onPort:error: 返回一个指示符,以确定您是否可以尝试连接套接字。
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.