这种情况应该使用 TcpClient 吗?

发布于 2024-09-02 03:53:25 字数 1028 浏览 0 评论 0原文

我必须与 iPhone 进行通信。我有它的 IP 地址和端口(通过 Bonjour 获得)。

我需要发送一个“0x50544833”(或类似的十六进制数字)的标头,然后是数据的大小(如下),然后是数据本身。

数据只是一个看起来像这样的字符串:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE plist SYSTEM "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>clientName</key>
        <string>XXX</string>
        <key>clientService</key>
        <string>0be397e7-21f4-4d3c-89d0-cdf179a7e14d</string>
        <key>registerCode</key>
        <string>0000</string>
    </dict>
</plist>

要求还规定我必须以小端格式发送数据(我认为这是英特尔的默认格式)。

所以它是:hex_number + 数据大小 + string_with_the_above_xml。

我需要将其发送到 iPhone 并阅读响应。

根据您的经验,发送此数据(并读取响应)的最佳方式是什么?

更新:我没有编写 iPhone 软件。它使用 Tcp/Ip。该端口取决于操作系统,但我见过它的范围从 57xxx 到 60xxxx,但并非总是如此。该软件的 Mac 版本使用 Tcp/Ip。我无法访问其源代码,但我与它的开发人员联系,他向我解释了需要发送的数据的格式,然后,一旦 Bonjour 服务得到解决,“打开一个套接字并......”

I have to communicate with an iPhone. I have its IP Address and the port (obtained via Bonjour).

I need to send a header that is “0x50544833” (or similar, It’s an HEX number), then the size of the data (below) and then the data itself.

The data is just a string that looks like this:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE plist SYSTEM "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>clientName</key>
        <string>XXX</string>
        <key>clientService</key>
        <string>0be397e7-21f4-4d3c-89d0-cdf179a7e14d</string>
        <key>registerCode</key>
        <string>0000</string>
    </dict>
</plist>

The requirement also says that I must send the data in little endian format (which I think is the default for Intel anyway).

So it would be: hex_number + size of data + string_with_the_above_xml.

I need to send that to the iPhone and read the response.

What would be, according to your experience, the best way to send this data (and read the response)?

update: I didn’t write the iPhone software. It uses Tcp/Ip. The port depends upon the Operating System, but I’ve seen it ranging from 57xxx to 60xxxx, not always. The Mac version of this software uses Tcp/Ip. I have no access to its source code, but I am in contact with its developer, who explained me the format of the data I need to send and then, once the Bonjour service was resolved, “open a socket and …”

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

预谋 2024-09-09 03:53:25

是的,您可以在这种情况下使用 TcpClient。在这种情况下它将完美地工作。

Yes, you can use TcpClient for this scenario. It will work perfectly in this case.

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