简体   繁体   English

TcpClient是否应用于这种情况?

[英]Should TcpClient be used for this scenario?

I have to communicate with an iPhone. 我必须与iPhone通信。 I have its IP Address and the port (obtained via Bonjour). 我有它的IP地址和端口(通过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. 我需要发送的标头是“ 0x50544833”(或类似的,它是一个十六进制数字),然后是数据的大小(如下),然后是数据本身。

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). 该要求还指出,我必须以小字节序格式发送数据(无论如何,我认为这是Intel的默认设置)。

So it would be: hex_number + size of data + string_with_the_above_xml. 它将是:十六进制数字+数据大小+ string_with_the_above_xml。

I need to send that to the iPhone and read the response. 我需要将其发送到iPhone并阅读响应。

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. 更新 :我没有写iPhone软件。 It uses Tcp/Ip. 它使用Tcp / Ip。 The port depends upon the Operating System, but I've seen it ranging from 57xxx to 60xxxx, not always. 该端口取决于操作系统,但是我看到的范围从57xxx到60xxxx,并不总是如此。 The Mac version of this software uses Tcp/Ip. 此软件的Mac版本使用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 …” 我无法访问其源代码,但是我正在与其开发人员联系,后者向我解释了我需要发送的数据格式,然后在Bonjour服务解决后,“打开套接字并...”

Yes, you can use TcpClient for this scenario. 是的,您可以在这种情况下使用TcpClient。 It will work perfectly in this case. 在这种情况下,它将运行完美。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM