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);

}

}

相关文章:

  • 2021-07-19
  • 2021-06-14
  • 2022-02-11
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2021-08-20
  • 2022-12-23
  • 2022-01-01
相关资源
相似解决方案