iPhone: Bonjour NSNetService IP address and port

前端 未结 3 1449
礼貌的吻别
礼貌的吻别 2021-01-31 05:47

Excuse my iPhone/Objective-C newbie status please!

I\'ve found my HTTP server using NSNetServiceBrowser, but now I just want the IP address and port of the service found

3条回答
  •  盖世英雄少女心
    2021-01-31 06:08

    The NSNetService you get back in the callback isn't ready to be used. You have to call the following method to get addresses for it:

    - (void)resolveWithTimeout:(NSTimeInterval)timeout;
    

    Implement the NSNetService delegate method to find out when it resolves:

    - (void)netServiceDidResolveAddress:(NSNetService *)sender;
    

    At that point, there should be at least one address in the service.

    Also, take care to read the documentation and the header file carefully! There is some complexity to the issue here that I've glossed over.

提交回复
热议问题