YangLei's

导航

 

C# TcpClient在连接成功后无法检测连接状态,即使对方关闭了网络连接。以下扩展可检测连接状态:

static class TcpClientEx {

public static bool IsOnline(this TcpClient c) {

return !((c.Client.Poll(1000, SelectMode.SelectRead) && (c.Client.Available == 0)) || !c.Client.Connected);

}

}

posted on 2015-03-02 17:35  大狼熙熙  阅读(957)  评论(0编辑  收藏  举报