摘要: C# TcpClient在连接成功后无法检测连接状态,即使对方关闭了网络连接。以下扩展可检测连接状态:public static class TcpClientEx { public static bool IsOnline(this TcpClient c) { return !((c.Client.Poll(1000, SelectMode.SelectRead) && (c.Client.Available == 0)) || !c.Client.Connected); } } NetworkStream的Read方法在关闭连接时会... 阅读全文
posted @ 2014-02-20 09:06 Lexy 阅读(33100) 评论(2) 推荐(3) 编辑