如何设置UDPClient的ReceiveBufferSize?或者设置有意义吗? C#
我正在实现 UDP 数据传输。我有几个关于 UDP 缓冲区的问题。
我正在使用 UDPClient 进行 UDP 发送/接收。我的宽带带宽是 150KB/s(字节/秒,而不是bps)。
我向 27 台主机发送了 500B 数据报
如果收到,27 台主机将发回 10KB 数据报。
那么,我应该收到 27 条回复,对吧?但是,我平均只收到 8 - 12 条回复。
然后我尝试将响应的大小减小到 500B,是的,我收到了全部。
我的想法是,如果所有 27 台主机几乎同时发回 10KB 响应,则传入流量将为 270KB/s(可能),这超出了我的传入带宽,因此会发生丢失。我说得对吗?
但我认为即使传入的流量超过了带宽,Windows是否应该将数据报放入缓冲区并等待接收?
然后我怀疑也许我的 UdpClient 的 ReceiveBufferSize 太小了?默认是8092B??
我不知道我在这些方面是否还好。请给我一些帮助。
I am implementing a UDP data transfer thing. I have several questions about UDP buffer.
I am using UDPClient to do the UDP send / receive. and my broadband bandwidth is 150KB/s (bytes/s, not bps).
I send out a 500B datagram out to 27 hosts
27 hosts send back 10KB datagram back if they receive.
So, I should receive 27 responses, right? however, I only get averagely 8 - 12 instead.
I then tried to reduce the size of the response down to 500B, yes, I receive all.
A thought of mine is that if all 27 hosts send back 10KB response at almost same time, the incoming traffic will be 270KB/s (likely), that exceeds my incoming bandwidth so loss happens. Am I right?
But I think even if the incoming traffic exceeds the bandwidth, is the Windows supposed to put the datagram in the buffer and wait for receive?
I then suspect that maybe the ReceiveBufferSize of my UdpClient is too small? by default, it is 8092B??
I don't know whether I am all right at these points. Please give me some help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UDP协议不保证数据包的传送,如果需要保证数据包的传送,您应该切换到TCP。
UDP 更适合丢失数据包比等待数据包找到路径更好的应用程序。即流媒体或类似的东西。
有关更多信息,请参阅维基百科。
The UDP protocol does not guaratnee delivery, you should switch to TCP if you need to guaratnee packet delivery.
UDP is better suited to apps where loosing a packet is better than waiting for a packet to find its way to you. i.e. streaming media or somehting similar.
See wikipedia for more.