NSHost 花费了很长的时间
我有一个 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: '
I have an iPhone app that is a client for an existing server application.
I am using the following code to connect, and this code was working fine. Today I started work on the project, and something odd is happening.
When I click "Connect" NSHost takes about 30-45 seconds to resolve and connect to the host. Once the connection is established, data transfer speeds are normal and fast.
I have the original client software (PC Application) connecting to the same server, and the connection is handled immediately!!
Perhaps someone can shed some light on the subject...
-(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.";
}
}
//I am also now getting these warnings.**.. wth?! :)
- warning: no '+hostWithAddress:' method found
- warning: (Messages without a matching method signature
- warning: no '+hostWithName:' method found
- warning: 'NSStream' may not respond to '+getStreamsToHost:port:inputStream:outputStream:'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已将代码更新为以下内容,这解决了我的问题。
I have updated my code to the following, which has resolved my issue.
这是使用 cfsockets
http://randomsnippetsofusefulstuff.blogspot.com/进行联网的另一种方式
here is another way of networking using cfsockets
http://randomsnippetsofusefulstuff.blogspot.com/