isHostReachable method

Future<AddressCheckResult> isHostReachable(
  1. AddressCheckOptions options
)

Implementation

Future<AddressCheckResult> isHostReachable(
  AddressCheckOptions options,
) async {
  Socket? sock;
  try {
    sock = await Socket.connect(
      options.address ?? options.hostname,
      options.port,
      timeout: options.timeout,
    )
      ..destroy();
    return AddressCheckResult(
      options,
      isSuccess: true,
    );
  } catch (e) {
    sock?.destroy();
    return AddressCheckResult(
      options,
      isSuccess: false,
    );
  }
}