Here you can find the source of isPortUsing(String host, int port)
Parameter | Description |
---|---|
host | a parameter |
port | a parameter |
public static boolean isPortUsing(String host, int port)
//package com.java2s; //License from project: Apache License import java.io.*; import java.net.InetAddress; import java.net.Socket; public class Main { /**/*from w w w .ja va2 s . c o m*/ * Check if a port is being used in the specified host * * @param host * @param port * @return */ public static boolean isPortUsing(String host, int port) { boolean flag = false; try { InetAddress theAddress = InetAddress.getByName(host); Socket socket = new Socket(theAddress, port); flag = true; } catch (IOException e) { //do nothing } return flag; } }