如何在 C# 中确定 UDP 套接字缓冲区大小?
我将连续发送 ECG 数据的 UDP 数据包(1500 字节)长达 5 分钟。我可以使用什么安全的 socket.ReceiveBufferSize
?我将过滤这些数据并绘制传入的数据。我想防止任何缓冲区问题。
I'll be sending UDP packets (1500 bytes) of ECG data continuously for up to 5 minutes. What is a safe socket.ReceiveBufferSize
I could use? I'll be filtering this data and plotting the data as it comes in. I want to prevent any buffer issues.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
计算或估计 maxPacketsPerSec 的值,为
howManySecondsToBuffer
选择一个安全/慷慨的值,例如 5 范围内的值(至少可以承受最严重的垃圾)收集暂停)到 60(如果你完全偏执的话,甚至是完整的 300 秒),然后进行数学计算。更重要的是:尽快将字节从套接字接收缓冲区中取出,将它们交给某个队列,该队列由其他线程或多个线程(如果需要)处理。这样,您的应用内队列将缓冲与 RAM 一样多的数据,并且您的 Socket.ReceiveBufferSize 值将变得不那么重要。
Figure out or estimate your value for
maxPacketsPerSec
, choose a safe/generous value forhowManySecondsToBuffer
, something in the range of, say, 5 (to at least weather even the worst garbage collection pauses) to 60 (or even the full 300 seconds if you are completely paranoid), and then do the math.More important though: Heave the bytes out of the socket receive buffer as fast as you can, hand them over to some queue which is processed by some other thread, or multiple threads, if need be. That way your in-app queue will buffer as much as you have RAM, and your
Socket.ReceiveBufferSize
value will become less important.如果你想防止任何问题,你需要使用 TCP。
如果您使用 udp,您可能会丢失数据或得到错误的数据包序列。
If you want to prevent any issues you need to use TCP.
In case you are using udp you are posibly loss data or get wrong sequence of packets.