When trying to connect to my website using NSURLConnection as shown below the application fails rather frequently, as it's not able to resolve the server name (MyMac.local.). This url address was discovered previously using bonjour. Usually this issue is resolved by opening up Safari Bonjour Bookmarks, but this is not really a solution. What I am looking for is to resolve the host address and then connect to it consistently.

To reproduce this issue I :
1.) Start the http service on MyMac.local.
2.) Connect to it from another client (Success)
3.) Put MyMac.local. to sleep
4.) Connect to it from another client (Fails - Server asleep - No problem)
5.) Wake MyMac.local. up
6.) Connect to it from another client (Fails - PROBLEM)
7.) Open up Safari Book Marks to find my service running on MyMal.local. listed or run "dscacheutil -flushcache"
8.) Connect to it from another client (Success - Problem resolved)

When it's working dumping the dscacheutil (dscacheutil -cachedump - entries host) shows the following

Working :
Host 05/03/09 12:21:51 05/03/09 12:19:51 0 7 120
                     Key: h_aliases:polaris.local. ipv4:1 ipv6:1
                     Key: h_aliases:polaris.local. ipv6:1
                     Key: h_aliases:polaris.local. ipv4:1
                     Key: h_name:Polaris.local ipv4:1 ipv6:1
                     Key: h_name:Polaris.local ipv6:1
                     Key: h_name:Polaris.local ipv4:1

However once the server has been put to sleep it appears as.

Problem :
Host 05/03/09 13:19:57 05/03/09 12:23:25 2 2 3600 YES
                     Key: h_name:polaris.local ipv4:1 ipv6:1

Even after waking it back up does not change this. However flushing the cache also resolve the problem.

I read up on NSNetService's resolve method, but that requires a service name which I don't have. Once I discover the server I construct a URL and store this in my configuration. Is there a way to resolve the name from a URL ?

This is an example client I use to debug this issue.

int main (int argc, const char * argv[])
{
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   NSString * hostAddressString;
   if (argc == 2)
   {
     hostAddressString = [NSString stringWithUTF8String:argv[1]];
   }
   else
   {
     hostAddressString = @"http://MyMac.local.:8080";;
   }
   NSLog(@"Connect to  : %@",hostAddressString);
NSURLRequest * request=[NSURLRequest requestWithURL:[NSURL URLWithString:hostAddressString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
   NSURLResponse * response;
   NSError * error;
   NSData * data;
data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; //NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
   if (!data)
   {
     NSLog(@"Pre-connect failed");
   }
   else
   {
NSString * output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
     NSLog(output);
   }
   if (error)
   {
NSLog(@"Pre-connect failed : %i %@ %@",[error code],[error domain],[error localizedDescription]);
   }
   [pool drain];
   return 0;
}



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to