我可以确定传入 TCP 客户端流上排队的数据量(在 C# 中)吗?

发布于 2024-12-07 14:15:01 字数 111 浏览 2 评论 0原文

我有一个连接到服务器的小型 TCP 客户端。连接期间定期 我希望能够查询流以查看排队的数据量(发送方可能比接收方更快,所以我希望能够偶尔丢弃数据包) 有没有办法确定 C# 中 TCP 客户端流上排队的数据量?

I have 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#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伪心 2024-12-14 14:15:01

您可以使用 TcpClient.Available为此的财产。

来自 MSDN:

类型:System.Int32

从接收到的数据的字节数
网络并可供阅读。

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.

临走之时 2024-12-14 14:15:01

Socket.AvailableTcpClient.Available 可以告诉您套接字已排队的字节数。但请注意,它不会告诉您有多少“数据包”排队,因为 TCP 有意隐藏“数据包”的概念。对于操作系统和您的应用程序来说,TCP 套接字仅代表字节流。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文