如何从 -[NSNetService 地址] 派生地址和端口,以便我可以将其与 NSURL 一起使用

发布于 2024-08-16 08:27:05 字数 518 浏览 4 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔小萌 2024-08-23 08:27:05

也许可以从 -hostName-port 构建一个?

Construct one from -hostName and -port perhaps?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文