我可以确定传入 TCP 客户端流上排队的数据量(在 C# 中)吗?
我有一个连接到服务器的小型 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 TcpClient.Available为此的财产。
来自 MSDN:
You can use the TcpClient.Available property for that.
From MSDN:
Socket.Available
和TcpClient.Available
可以告诉您套接字已排队的字节数。但请注意,它不会告诉您有多少“数据包”排队,因为 TCP 有意隐藏“数据包”的概念。对于操作系统和您的应用程序来说,TCP 套接字仅代表字节流。There's
Socket.Available
andTcpClient.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.