Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class Main { private static final String[] host_arr = {}; public static String HOST = ""; @SuppressWarnings("unused") public static void selectServer2() { for (String host : host_arr) { HttpURLConnection conn = null; try { conn = (HttpURLConnection) new URL(host).openConnection(); conn.setConnectTimeout(6000); int result = conn.getResponseCode(); String re = conn.getResponseMessage(); if (result == HttpURLConnection.HTTP_OK) { HOST = host;// break; } else { } } catch (MalformedURLException e) { } catch (IOException e) { } finally { if (conn != null) { conn.disconnect(); conn = null; } } } } }