如何使用C#UdpClient发送大量数据? [英] How to send large data using C# UdpClient?

查看:645
本文介绍了如何使用C#UdpClient发送大量数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送大量的数据使用C#UdpClient(超过50 MB)的。

I'm trying to send a large amount of data (more than 50 MB) using C# UdpClient.

所以刚开始我将数据分割成65507字节的块以及在循环中向他们发送

So at first I split the data into 65507 byte blocks and send them in a loop.

for(int i = 0; i < packetCount; i++)
   myUdpClient.Send(blocks[i], block[i].Length, remoteEndPoint);



我的问题是,只有第一个包可以被接收。
期间迅速networkload增加发送的第一分组到100%,并且不能接收那么其他的数据包。

My problem is that only the first packets can be received. During sending the first packet the networkload increases rapidly to 100%, and then the other packets cannot be received.

我希望得到尽可能多的数据可以通过如可能的。

I want to get as much data throughput as possible.

我为我的英语对不起!
感谢您的帮助提前。

I'm sorry for my English! Thanks for your help in advance.

推荐答案

我不知道.NET实现具体而言,它可能是缓冲数据,但是UDP数据报通常由链路MTU,这是1500关于正常以太网限制(减去20字节的IP报头和8字节的UDP报头)。

I don't know about .Net implementation specifically, it might be buffering your data, but UDP datagram is normally limited by the link MTU, which is 1500 on normal ethernet (subtract 20 bytes for IP header and 8 bytes of UDP header.)

UDP明确允许删除并重新排序的数据包,而且也没有流控制在TCP。

UDP is explicitly allowed to drop and reorder the datagrams, and there's no flow control as in TCP.

超出插座发送缓冲区在发送方将有网络协议栈忽略后面的发送尝试,直到缓冲空间再次可用(您需要检查发送()对于这一点。返回值)

Exceeding the socket send buffer on the sender side will have the network stack ignore following send attempts until the buffer space is available again (you need to check the return value of the send() for that.)

我会强烈建议使用TCP进行大文件传输下去。 TCP给你排序(你没有保持跟踪删除并重新排序的数据包)。它拥有先进的流量控制(这么快发件人不会压倒一个缓慢的接收器。)它也做路径MTU发现(即找出最佳数据打包,避免IP分片)。否则,你将不得不重新实现这些功能大部分自己。

I would strongly recommend going with TCP for large file transfers. TCP gives you sequencing (you don't have to keep track of dropped and re-ordered packets.) It has advanced flow control (so fast sender does not overwhelm a slow receiver.) It also does Path MTU discovery (i.e. finds out optimal data packetization and avoids IP fragmentation.) Otherwise you would have to re-implement most of these features yourself.

这篇关于如何使用C#UdpClient发送大量数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆