开发者

NSNetService call backs for IP change?

What is the best way to track an IP address of a netservice that may change? (switching back and forth between en0, en1 f开发者_Go百科or example)

After calling startMonitoring, you get call backs when the TXT Record data changes, but I have found no obvious way to be notified if the IP changes.

Currently, I just re-browse when a connection fails and check to see if the IP has changed. I hope this isn't the cleanest way to do it. Any ideas?


A minor misunderstanding of the nature of NSNetService might exist - that's causing your confusion.

You should keep your reference to NSNetService, and when you want to connect to it, you tell it to:

- (void)resolveWithTimeout:(NSTimeInterval)timeout

That call returns immediately and your NSNetServiceDelegate is told when an address has been found for that service. Ideally, you work within these limits.

If you really just want to actively follow IP address changes, then maintain an instance of each NSNetService, call startMonitoring() on each, and maintain a record of each netServiceDidResolveAddress() callback that your delegate receives.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜