title: Client not discovering bonjour service
body: <p>I have just started learning to design iphone apps and I am trying to set up a client server environment. As a starter I would like to first make sure that the service I publish is visible to the client. I have written server and client codes wit help from Apple's Docs. However I find that though my service is getting published (netServiceWillPublish(NSNetService *)sender is called), my client is not identifying this service. At the client's side the delegate function netServiceBrowserWillSearch:(NSNetServiceBrowser *)browser is called making me believe that the client is searching for the service. However the didFindService delegate function is never called. i am stumped as to why this is not working. I have followed the sample codes for the client side from various places and my code matches theirs. Some help on this would be greatly appreciated</p>
  
  <p>Also I have the following questions  </p>
  
  <ol>
  <li><p>Can the service name (that comes along with the transport level protocol) be any string? Or does it have to be specified in <a href="http://www.dns-sd.org/ServiceTypes.html" rel="nofollow">http://www.dns-sd.org/ServiceTypes.html</a>. Also what purpose does this solve apart from service discovery.</p></li>
  <li><p>When I print out the details of the NSNetService object at the server's side (After setting up the socket and starting the service) the hostname is printed as (null) and there are no addresses being displayed. technically when a service is opened shouldn't these be set to values? If yes could someone please tell me where I am going wrong in my code?</p></li>
  </ol>
  
  <p>I have attached the client and server code blocks of my project where the publishing and browsing of servicing is done. Help is extremely appreciated as I am stuck in my work with this issue.</p>
  
  <p>This is the code snippet at the client side that browses for the services</p>
  
  <pre><code>NSNetServiceBrowser *serviceBrowser;
  serviceBrowser = [[NSNetServiceBrowser alloc] init];
  [serviceBrowser setDelegate:self];
  [serviceBrowser searchForServicesOfType:@"_http._tcp." inDomain:@"local."];
  </code></pre>
  
  <p>This is the code snippet at the server side that publishes the service</p>
  
  <pre><code>BOOL                success;
  int                 fd;
  int                 err;
  int                 junk;
  struct sockaddr_in  addr;
  NSInteger           port;
  
  port = 0;
  
  fd = socket(AF_INET, SOCK_STREAM, 0);
  success = (fd != -1);
  if(success) {
      memset(&amp;addr, 0, sizeof(addr));
      addr.sin_len = sizeof(addr);
      addr.sin_family = AF_INET;    
      addr.sin_port = 0;
      addr.sin_addr.s_addr = INADDR_ANY;
      err = bind(fd, (const struct sockaddr*) &amp;addr, sizeof(addr));
      success = (err == 0);
  }
  
  if (success) {
      err = listen(fd, 5);
      success = (err == 0);
  }
  
  if (success) {
      socklen_t addrLen;
      addrLen = sizeof(addr);
      err = getsockname(fd, (struct sockaddr *) &amp;addr, &amp;addrLen);
      success = (err == 0);
  
      if (success) {
          assert( addrLen = sizeof(addr));
          port = ntohs(addr.sin_port);
      }
  }
  
  if (success) {
      CFSocketContext context = { 0, (__bridge void *) self, NULL, NULL, NULL };
  
      assert(self-&gt;_listeningSocket == NULL);
      self-&gt;_listeningSocket = CFSocketCreateWithNative(NULL, fd, kCFSocketAcceptCallBack, AcceptCallBack, &amp;context);
  
      success = (self-&gt;_listeningSocket != NULL);
  
      if (success) {
          CFRunLoopSourceRef rls;
          fd = -1;    //listeningSocket is now responsible for closing the socket
          rls = CFSocketCreateRunLoopSource(NULL, self.listeningSocket, 0);
          assert(rls != NULL);
          CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
          CFRelease(rls);
      }
  }
  
  if (success) {
      self.netService = [[NSNetService alloc] initWithDomain:@"local." type:@"_http._tcp." name:@"test" port:port];
      success = (self.netService != nil);
  }
  if (success) {
      self.netService.delegate = self;
      [self.netService publishWithOptions:NSNetServiceNoAutoRename];
  
  }
  
  if (success) {
      assert(port != 0);
      [self serverDidStartOnPort:port];
  }
  else {
      [self stopServer:@"Start Failed"];
      if (fd != -1) {
          junk = close(fd);
          assert(junk == 0);
      }
  }
  </code></pre>
  
  <p>This is the code snippet that tells that the service is published and prints out the details of my NSSocket object</p>
  
  <pre><code>- (void)netServiceWillPublish:(NSNetService *)sender {
      NSLog(@"This function is getting called");
      NSLog(@"sender.name %@",sender.name);
      NSLog(@"sender.addresses %@",sender.addresses);
      NSLog(@"sender.domain %@",sender.domain);
      NSLog(@"sender.hostname %@",sender.hostName);
      NSLog(@"sender.type %@",sender.type);
      NSLog(@"sender.port %d",sender.port);
  }
  </code></pre>
  
  <p>Thanks<br>
  Vivek</p>