Cocoa Touch Bonjour如何处理NSNetService地址和uint8_t
我正在尝试使 iOS 应用程序与使用 Bonjour 并使用 HTTP 命令的服务器进行通信。到目前为止,我已经能够找到本地域并找到我正在寻找的特定服务。我能够解析服务的地址,但我不知道如何从该地址中获取有用的内容。 NSNetService 的地址是一个 NSData 对象,我不知道如何处理它。我需要发送 GET 和 PUT 等命令。哪些可可类可以处理这样的事情?
我还尝试从服务获取输入和输出流,但它们似乎是非常低级别的流,我不知道如何正确处理缓冲区等。
[service getInputStream:&inputStream outputStream:&outputStream]
NSOutputStream write 方法接受一个 uint8_t 缓冲区,我不知道如何创建它。 NSInputStream read 方法返回一个 uint8_t 缓冲区,我不知道如何解释它。
我可以使用终端命令与该服务器进行通信。例如,向它发送命令 LIST 会导致它打印出我正在查找的文件列表。我如何在 Cocoa 中发送和获取这样的信息?
I'm attempting to make an iOS app communicate with a server that uses Bonjour and uses HTTP commands. So far I have been able to find the local domain and locate the particular service I'm looking for. I am able to resolve the address of the service, but I don't know how to get something useful out of the address. The address from the NSNetService is a NSData object and I have no idea what to do with it. I need to send commands like GET and PUT. What cocoa classes handle things like this?
I also tried getting input and output streams from the Service, but they seem to be extremely low level streams and I don't know how to properly deal with buffers and all that.
[service getInputStream:&inputStream outputStream:&outputStream]
the NSOutputStream write method takes in a uint8_t buffer which I have no idea how to create.
the NSInputStream read method returns a uint8_t buffer and I don't know how to interpret it.
I am able to communicate with this server using terminal commands. For instance, sending it the command LIST causes it to print out the list of files I am looking for. How do I send and get information like this in Cocoa?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将数据写入输出流,从而将其发送到服务器:
您可以像这样发送任何数据,只需将其放入
NSData
对象中即可。要从服务器接收数据,请在输入流的
NSStreamDelegate
中使用此代码:查看 Apple 的 CocoaEcho 示例代码。它应该对你有帮助。
To write data to the output stream, therefore sending it to the server:
You can send any data like this, just put it in a
NSData
object.To receive data from the server use this code in the input stream's
NSStreamDelegate
:Take a look at Apple's CocoaEcho Sample Code. It should help you.