isHostReachable method

Future<bool> isHostReachable(
  1. InternetAddress host, [
  2. bool debug = true
])

Implementation

Future<bool> isHostReachable(
  InternetAddress host, [
  bool debug = true,
]) async {
  Socket? sock;
  try {
    sock = await Socket.connect(
      host,
      port,
      timeout: timeout,
    );
    sock.destroy();
    if (debug) {
      if (kDebugMode) {
        print('connect Internet Address: $host = true');
      }
    }
    return true;
  } catch (e) {
    sock?.destroy();
    if (kDebugMode) {
      print('connect Internet Address: $host = false');
    }
    return false;
  }
}