开发者

Can I determine how much data is queued up on an incoming TCP client stream (in C#)?

I have开发者_StackOverflow中文版 a small TCP client that connects to a server. Periodically during the connection I'd like to be able to query the stream to see how much data has queued up (the sender may be faster than the receiver, so i'd like to be able to throw away packets occasionally) Is there any way to determine how much data is queued up on a TCP client stream in C#?


You can use the TcpClient.Available property for that.

From MSDN:

Type: System.Int32

The number of bytes of data received from the network and available to be read.


There's Socket.Available and TcpClient.Available to tell you how many bytes the socket has queued up. Note, though, it doesn't tell you how many "packets" were queued up, as TCP makes a point to hide the notion of "packets". To the OS and your app, a TCP socket just represents a stream of bytes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜