gpt4 book ai didi

c# - TcpListener:如何检测客户端断开连接?

转载 作者:太空狗 更新时间:2023-10-29 21:48:07 26 4
gpt4 key购买 nike

我如何检测客户端何时与 TcpListener 断开连接?

我的每个客户都在一个单独的线程中处理。

最佳答案

NetworkStream.Read ,或者取决于您在代码中使用的内容可能是 TCPClient.GetStream更合适,但基本相同的答案。

来自文档:

This method reads data into the buffer parameter and returns the number of bytes successfully read. If no data is available for reading, the Read method returns 0. The Read operation reads as much data as is available, up to the number of bytes specified by the size parameter. If the remote host shuts down the connection, and all available data has been received, the Read method completes immediately and return zero bytes.

关于c# - TcpListener:如何检测客户端断开连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1202154/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com