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.port,
      timeout: options.timeout,
    )
      ..destroy();
    return AddressCheckResult(
      options,
      true,
    );
  } catch (e) {
    sock?.destroy();
    return AddressCheckResult(
      options,
      false,
    );
  }
}