Problème sur méthode "ping"
Bonjour tout le monde,
J'ai un problème au niveau ma methode de ping, elle renvoie toujours "false" !! meme dans le cas ou j'ai une connexion, je pense que tout est bon mais je pense aussi que j'ai oublié quelque chose !! :aie:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
public static boolean ping() {
int timeout = 3000;
String url = "http://www.google.fr";
System.out.println("ping");
try {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setConnectTimeout(timeout);
connection.setReadTimeout(timeout);
connection.setRequestMethod("HEAD");
int responseCode = connection.getResponseCode();
return (200 <= responseCode && responseCode <= 399);
} catch (IOException exception) {
System.out.println("Connexion Out : "+exception.getMessage());
return false;
}
} |
merci d'avance :)