如何通过网络快速发送数据?
我有很多这样的数据 1:0x00a4c7d9fb3849...
2:0x79821309bd789c7689c97...
3:0x0178dce67fe898...
每秒超过100个,速度是最重要的(网络总是繁忙)。
我应该使用什么来传输我的数据(tcp/ip、管道、via 等)?
我应该如何序列化它(BinaryFormatter、Xml、用户定义或任何更好的建议)?
i have lots of data like this
1:0x00a4c7d9fb3849...
2:0x79821309bd789c7689c97...
3:0x0178dce67fe898...
they are more than 100 per second and speed is the most important thing(network is always busy).
what should i use to transfer my data(tcp/ip, pipes, via, etc)?
how should i serialize it(BinaryFormatter,Xml,User defined or any better advices)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
每秒 100 次可能没有你想象的那么糟糕。
如果每个字节都是 100 个字节(100 个数字应该适合,没问题),100x100 就是每秒 10000 个字节,或 10Kbps。
我会使用我最熟悉的任何东西,如果第一个解决方案不起作用,我会担心速度。您构建第一个解决方案的想法将使第二个解决方案更容易构建,并且您将更快或同时获得最终产品,除非更少的挫败感。
100 a second might not be as bad as you think.
If each of those are 100 bytes (100 digits should fit in that, no problem), 100x100 is 10000 bytes a second, or 10Kbps.
I'd use whatever I was most familiar with, and worry about speed if the first solution didn't work. The ideas you get building that first solution will/would make a second solution much easier to build, and you'll get to the final product faster or at the same time you would have, except with less frustration.
如果您要发送大量数据,并且数据不重要,那么 UDP 是最佳选择。但是,这可能会丢失数据包(您可能会通过网络丢失一个数据集)。如果您的数据正在执行诸如更新实时图表之类的操作,这通常很好,因为缺失值并不重要。
但是,如果丢失数据很严重,那么 TCP/IP 将是通过网络发送数据的最佳选择。鉴于数据速率很高,您最好制作自己的用户定义的二进制格式,并且仅发送/接收原始字节。使用 Xml 会更加繁琐(这意味着更多的开销)。即使 BinaryFormatter 也会增加一些开销,因为序列化往往会增加一些超出绝对必要的开销。
If you're sending lots of data, and if the data isn't critical, then UDP is the best option. However, this will potentially lose packets (you may lose one of your datasets across the wire). This is often fine, if your data is doing something like updating a real-time chart, since a missing value doesn't really matter.
If, however, missing data is critical, then TCP/IP will be your best option for sending data across the network. Given the high rate of data, you'll be best off making your own user-defined binary format, and just sending/receiving raw bytes. Using Xml will be much, much chattier (which means more overhead). Even BinaryFormatter will add some overhead, since the serialization tends to add a bit more than absolutely necessary.
每秒 100 个这些字符串看起来并不是什么大问题(或者字符串必须很长)。
二进制总是比它的字符串代表更加简洁。您甚至可以先打包它(使用 zip 或其他任何东西)
如果您想完全控制发送,TCP/IP 将是一个不错的选择。
100 per second of these strings doesn't look like too much of an issue (or the strings must be very long).
binary is always much more condensed than it's string representative. You could potentially even pack it first(using zip or anything else)
TCP/IP would be a good bet if you want full control over sending.
这看起来像二进制数据(例如可以打包到 byte[] 中而不是使用字符串的数据)。为了获得最佳效率,您可以在 TCP/IP 之上设计自己的协议(使用 TCP,甚至 UDP),如果网络负载是一个大问题,甚至可以动态压缩数据。确保您不会发送许多小块,而是通过网络发送较大的块(例如,1400 字节可能是一个不错的大小)。
This looks like binary data (e.g. data which can be packed into byte[] instead of using strings). For best efficiency, you can design your own protocol on top of TCP/IP (using TCP, or even UDP), and maybe even compress the data on the fly, if network load is a big issue. Make sure that you don't send many small chunks, but rather send larger (e.g. 1400 bytes may be a good size) blocks across the network.