开发者

How to determine UDP socket buffer size in C#?

I'll be sending UDP packets (1500 bytes) of ECG data continuously for up to 5 minutes. What is a safe socket.ReceiveBufferSize I cou开发者_如何转开发ld use? I'll be filtering this data and plotting the data as it comes in. I want to prevent any buffer issues.


int packetSize = 1500; // as stated in the question
int safeBufferSize = maxPacketsPerSec * packetSize * howManySecondsToBuffer;

Figure out or estimate your value for maxPacketsPerSec, choose a safe/generous value for howManySecondsToBuffer, 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜