开发者

To find amount of data available in socket

Hai, Without using "Socket.Availabl开发者_如何转开发e". How could we find the number of bytes available in socket in C#. Could anybody found help me.


Socket.Available is pretty much the closest you'll get here, but this still only tells you what is available locally, rather than what the socket is going to deliver. IMO, the most reliable approach here is to implement your network code so that you know how much data is expected (in advance, perhaps simply with a length marker), and then use (for example) async stream-reading to pull that data from the socket until either you have consumed exactly that much data, or you timeout. Then the answer to "how much more do I expect" is simply "how much did I expect originally" - "how much have I read so far".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜