主机端口可用
/* 时代Java 提 供 */ //package com.nowjava; import java.io.IOException; import java.net.Socket; public class Main { public static void main(String[] argv) throws Exception { String host = "nowjava.com"; int port = 2; System.out.println(isPortAvailable(host, port)); } public static boolean isPortAvailable(String host, int port) { Socket socket = null; boolean available = false; try { socket = new Socket(host, port); available = true;/*n o w j a v a . c o m 提 供*/ } catch (IOException e) { // no-op } finally { if (socket != null) { try { sock