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:'