要查找插口可用的数据量 [英] To find amount of data available in socket

查看:160
本文介绍了要查找插口可用的数据量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海, 如果不使用Socket.Available。我们怎么能找到在C#中的插座可用的字节数。可能有人发现帮助我。

Hai, Without using "Socket.Available". How could we find the number of bytes available in socket in C#. Could anybody found help me.

推荐答案

Socket.Available 是pretty的多最接近你会来到这里,但仍只告诉你什么是可用的本地的,而不是什么套接字是要提供。国际海事组织,这里最可靠的办法是实现网络code,让你知道有多少数据的预计的(提前,也许只是一个长度标记),然后用(例如)异步流读取从插座中拔出的数据,直到你已经完全消耗如此多的数据,或者超时。然后回答多少做我期待,只不过是多少钱我才想到原来 - 有多少我至今读

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".

这篇关于要查找插口可用的数据量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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