isPortAvailable function

Future<bool> isPortAvailable(
  1. String host,
  2. int port
)

Implementation

Future<bool> isPortAvailable(String host, int port) async {
  ServerSocket? socket;
  try {
    socket = await ServerSocket.bind(host, port);
    return true;
  } catch (_) {
    return false;
  } finally {
    await socket?.close();
  }
}