ping static method

Future<PongData> ping({
  1. required String host,
  2. required int port,
})

Implementation

static Future<PongData> ping(
    {required String host, required int port}) async {
  UDP sendSocket = await UDP.bind(Endpoint.any());

  sendSocket.send(_buildPingPacket(), await Utils.hostLookup(host, port));

  var rawPong =
      (sendSocket.asStream().timeout(Duration(seconds: 1), onTimeout: (_) {
    throw ServerTimeoutException();
  }).first);

  return UnconnectedPing.fromBytes((await rawPong)!.data).pong;
}