我有一个 iPhone 应用程序,它是现有服务器应用程序的客户端。
我正在使用以下代码进行连接,并且此代码运行良好。今天我开始了这个项目,奇怪的事情正在发生。
当我单击“连接”时,NSHost 大约需要 30-45 秒才能解析并连接到主机。建立连接后,数据传输速度正常且快速。
我有原始客户端软件(PC应用程序)连接到同一台服务器,并且立即处理连接!
也许有人可以对这个主题有所了解......
-(IBAction)tryConnection{
[self showLogoffButtons];
iPhone_PNPAppDelegate *mainDelegate = (iPhone_PNPAppDelegate *)[[UIApplication sharedApplication] delegate];
settings=mainDelegate.settings;
[activityindicator startAnimating];
sendState=0;
NSHost* host;
//30-45 second pause happens here (since I am using an IP Address)
host = [NSHost hostWithAddress:settings.masterLocation];
//NSHost returns (eventually) with the correct connection.
if (!host) {
host = [NSHost hostWithName:settings.masterLocation];
}
if( host ) {
[NSStream getStreamsToHost:host port:[settings.masterPort intValue] inputStream:&iStream outputStream:&oStream] ;
if( nil != iStream && nil != oStream ) {
[iStream retain];
[oStream retain];
[iStream setDelegate:self];
[oStream setDelegate:self];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[iStream open];
[oStream open];
}else{
[self resetConnectionAndScreen];
self.navigationItem.prompt=@"Connection Error! Please check connection settings.";
}
}else{
[self resetConnectionAndScreen];
self.navigationItem.prompt=@"Connection Error! Please check connection settings.";
}
}
//我现在也收到这些警告。**.. wth?! :)
- 警告:找不到“+hostWithAddress:”方法
- 警告:(没有匹配方法签名的消息
- 警告:找不到“+hostWithName:”方法
- 警告:“NSStream”可能不会响应“+getStreamsToHost:port:inputStream:outputStream:”