
import 'dart:io';

abstract class INetworkService {
  Future<bool> isHostAvailable(String endpoint);
}

class NetworkService implements INetworkService{
  @override
  Future<bool> isHostAvailable(String endpoint) async {
    try {
      final result = await InternetAddress.lookup(endpoint.substring(endpoint.indexOf('//')+2).substring(0,endpoint.substring(endpoint.indexOf('//')+2).indexOf('/')));
      if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
        return true;
      } else{
        return false;
      }
    } on SocketException catch (_) {
      return false;
    }
  }
}

class NetworkException implements  Exception {
}
