Last active
January 31, 2016 19:54
-
-
Save gkastrinis/56a65658469edb778b31 to your computer and use it in GitHub Desktop.
PingUoA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.net.HttpURLConnection; | |
import java.net.SocketTimeoutException; | |
import java.net.URL; | |
import java.util.concurrent.TimeUnit; | |
public class Main { | |
final static int SLEEP_TIME = 7; | |
public static void main(String[] args) { | |
while (true) { | |
try { | |
final HttpURLConnection urlConn = (HttpURLConnection) new URL("http://www.uoa.gr").openConnection(); | |
urlConn.setConnectTimeout(1000 * 10); | |
urlConn.connect(); | |
if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) | |
System.out.println("Ping successful!!!"); | |
} catch (final SocketTimeoutException e) { | |
System.err.print("timeout..."); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
try { | |
System.err.println(" (wait...)"); | |
TimeUnit.MINUTES.sleep(SLEEP_TIME); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment