isPortAvailable function
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();
}
}