title: iPhone: Bonjour NSNetService IP address and port
body: <p>Excuse my iPhone/Objective-C newbie status please!</p>
  
  <p>I've found my HTTP server using NSNetServiceBrowser, but now I just want the IP address and port of the service found. </p>
  
  <p>I've got something like the following in my delegate method:</p>
  
  <pre><code>NSNetService* server = [serverBrowser.servers objectAtIndex:0];
  
  NSString            *name = nil;
  NSData              *address = nil;
  struct sockaddr_in  *socketAddress = nil;
  NSString            *ipString = nil;
  int                 port;
  uint                 i;
  for (i = 0; i &lt; [[server addresses] count]; i++)
  {
      name = [server name];
      address = [[server addresses] objectAtIndex:i];
      socketAddress = (struct sockaddr_in *)
      [address bytes];
      ipString = [NSString stringWithFormat: @"%s",
                  inet_ntoa (socketAddress-&gt;sin_addr)];
      port = socketAddress-&gt;sin_port;
      NSLog(@"Server found is %s %d",ipString,port);
  }
  </code></pre>
  
  <p>but the for loop is never entered, even though the delegate is called. Any ideas? Thanks!</p>