Here you can find the source of isPortUsing(String host, int port)
Parameter | Description |
---|---|
host | a parameter |
port | a parameter |
Parameter | Description |
---|---|
UnknownHostException | an exception |
public static boolean isPortUsing(String host, int port) throws UnknownHostException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; public class Main { /***//from w w w . ja va 2 s . c o m * true:already in using false:not using * @param host * @param port * @throws UnknownHostException */ public static boolean isPortUsing(String host, int port) throws UnknownHostException { boolean flag = false; InetAddress theAddress = InetAddress.getByName(host); try { Socket socket = new Socket(theAddress, port); flag = true; } catch (IOException e) { } return flag; } }