在 WP7 中将二进制数据发送到服务器的性能更好/更紧凑的方法是什么

发布于 2024-10-29 02:06:34 字数 206 浏览 2 评论 0原文

鉴于 Windows Phone 7 中没有直接的 tcp/socket 限制,我想知道性能开销最小和/或可以以最紧凑的方式发送的方式是什么。 我想我可以使用 HTTP(可能使用 HTTPWebRequest)将数据作为文件发送并将其编码为 Base64,但这会显着增加传输大小。我可以使用 WCF,但性能开销也会很大。 有没有一种方法可以发送纯二进制数据而不对其进行编码,或者有一些更快的方法吗?

Given the no direct tcp / socket limitation in Windows Phone 7 I was wondering what is the way that has the least performance overhead and/or can send it in the most compact way.
I think I can send the data as a file using HTTP (probably with an HTTPWebRequest) and encode it as Base64, but this would increase the transfer size significantly. I could use WCF but the performance overhead is going to be large as well.
Is there a way to send plain binary data without encoding it, or some faster way to do so?

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

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

发布评论

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

评论(2

↙厌世 2024-11-05 02:06:34

WP7 上的网络通信目前仅限于 HTTP。

考虑到这一点,您将必须允许 HTTP 标头作为传输的一部分包含在内。您可以通过不自己添加任何额外的标头(除非确实必须这样做)来帮助保持较小的大小。

就消息正文而言,您可以将内容保持得尽可能小。

将数据格式化为 JSON 通常会比将数据格式化为 XML 更小。

但是,如果您的数据始终采用特定格式,您可以将其作为原始数据包含在内。即,如果您知道数据的前 n 位/字节/字符代表一个事物,那么接下来的 y 位/字节/字符代表另一个事物,依此类推。您可以在没有任何(字段)标识符的情况下格式化数据。这仅取决于您需要什么。

Network communication on WP7 is currently limited to HTTP only.

With that in mind you're going to have to allow for the HTTP header being included as part of the transmission. You can help keep this small by not adding any additional headers youself (unless you really have to).

In terms of the body of the message then it's up to you to keep things as small as possible.

Formatting your data as JSON will typically be smaller than as XML.

If, however, your data will always be in a specific format you could just include it as raw data. i.e. if you know that the the data will have the first n bits/bytes/characters representing one thing, then next y bits/bytes/characters represent another, etc. you could format your data without any (field) identifiers. It just depends what you need.

束缚m 2024-11-05 02:06:34

如果你想发送二进制数据,那么肯定有人一直在使用原始套接字 - 请参阅
连接到连接的电脑从 WP7 通过打开一个到 localhost 的套接字

但是,除非你想编写自己的套接字服务器,否则 HTTP 是非常方便的。正如 Matt 所说,您可以在 HTTP 请求中包含二进制内容。为此,您可以使用标头:

Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-Length: your length

要实际设置这些标头,您可能需要将其作为多部分消息发送...请参阅诸如 使用 HTTPWebrequest 上传文件 (multipart/form-data)

AppHub 论坛上有一些优秀的示例代码 - http://forums.create.msdn.com/forums/p/63646/390044.aspx - 显示如何将二进制照片上传到 Facebook。

除非您的数据非常大,否则采用 Base64 编码的 4/3 可能会更容易:)(还有其他稍微更有效的编码类型,例如 Ascii85 - http://en.wikipedia.org/wiki/Ascii85)

If you want to send binary data, then certainly some people have been using raw sockets - see
Connect to attached pc from WP7 by opening a socket to localhost

However, unless you want to write your own socket server, then HTTP is very convenient. As Matt says, you can include binary content in your HTTP requests. To do this, you can use the headers:

Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-Length: your length

To actually set these headers, you may need to send this as a multipart message... see questions like Upload files with HTTPWebrequest (multipart/form-data)

There's some excellent sample code on AppHub forums - http://forums.create.msdn.com/forums/p/63646/390044.aspx - shows how to upload a binary photo to Facebook.

Unless your data is very large, then it may be easier to take the 4/3 hit of Base64 encoding :) (and there are other slightly more efficient encoding types too like Ascii85 - http://en.wikipedia.org/wiki/Ascii85)

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