2

i've two apps one of them runs an http server and the accesses it. I do not want to hard code the URL or the port in app which is client so I want to publish via bonjour the code for publishing is following

NSString *publishingDomain = @"local."; 
NSString *publishingName = @"some";
NSString* type = @"_http._tcp.";
int port = 1234;

netService = [[NSNetService alloc] initWithDomain:publishingDomain type:type name:publishingName port:port];    

netService.delegate = self;
[netService publish];

while the service is successfully published bonjour browser lists a bunch of ip addresses under service name but none of them can be used to connect to service whereas I can use both localhost:port and 127.0.0.1:port to access the web server. Bonjour browser does not list 127.0.0.1 as an ip address in the list.

what needs to be done differently to solve this?

user549164
  • 173
  • 2
  • 13
  • What exactly are the "bunch of ip addresses" that Bonjour Browser lists under _http._tcp? Do they point to other valid services running on your network or are they just rubbish? – Asmus Feb 24 '11 at 09:14
  • 1
    @Asmus they are all the ip addresses found when doing ifconfig except for 127.0.0.1 which shows up in ifconfig but not in bonjour browser – user549164 Feb 24 '11 at 22:41
  • Have you tried changing publishingDomain to an empty string? I believe NSNetService defaults to `local.` anyway. – Chris Mowforth Mar 17 '11 at 18:37
  • Is Bonjour the right approach for this? I think it will also publish your service to every other computer on the local network, even though none of them can access it from the network-facing IP address. It also means if your app is running on multiple computers on the subnet, whenever you want to connect to the one on your computer Bonjour will list all the ones running on other computers too, and you'll have to sift through them... – peterflynn Aug 16 '17 at 18:48

0 Answers0