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 = ""; public static final String Servlet_phone = "/servlet/PhoneServlet"; public static String HOST_PORT = ""; public static boolean selectServer() { boolean status = false; for (String host : host_arr) { String str = host + Servlet_phone; HttpURLConnection conn = null; try { conn = (HttpURLConnection) new URL(str).openConnection(); conn.setConnectTimeout(4000); int result = conn.getResponseCode(); if (result == HttpURLConnection.HTTP_OK) { HOST = str;// HOST_PORT = host; status = true; break; } else { } } catch (MalformedURLException e) { } catch (IOException e) { } finally { if (conn != null) { conn.disconnect(); conn = null; } } } return status; } }