如何从 -[NSNetService 地址] 派生地址和端口,以便我可以将其与 NSURL 一起使用
我想使用 CocoaHTTPServer 在不同实例之间设置点对点通信网络上的应用程序。设置服务器非常容易,但编写客户端则是另一回事了。
我的服务器通过 Bonjour 进行广播。我的客户端能够找到并解析该服务,但在获取可与 NSURL
一起使用的实际 IP 地址和端口时,我遇到了困难。
如果我调用[NSNetService地址]
,我会以NSData
对象数组的形式获得地址,这对于低级网络目的来说是很好的。但我的计划是在客户端使用 stringWithContentsOfURL:
来发出请求,因此我需要字符串或其他形式的地址。
这是一个明智的做法吗?如果是这样,我如何以可与 NSURL
配合使用的格式获取已解析的 NSNetService
的地址?
I'd like to use CocoaHTTPServer to set up peer-to-peer communication between different instances of an application on a network. Setting up the server was quite easy, but writing the client is another story.
I have the server broadcasting over Bonjour. My client is able to find and resolve the service, but I'm stuck when it comes to getting the actual IP address and port that I can use with NSURL
.
If I call [NSNetService addresses]
I get the addresses in the form of an array of NSData
objects, which is fine for low level networking purposes. But my plan was to use stringWithContentsOfURL:
on the client side to make requests, so I need the addresses as a string or something.
Is this a sensible approach? If so, how can I get the addresses of the resolved NSNetService
in a format that works with NSURL
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许可以从
-hostName
和-port
构建一个?Construct one from
-hostName
and-port
perhaps?