Java HTTP Port Find isLoclePortUsing(int port)

Here you can find the source of isLoclePortUsing(int port)

Description

true:already in using false:not using

License

Open Source License

Parameter

Parameter Description
port a parameter

Declaration

public static boolean isLoclePortUsing(int port) 

Method Source Code


//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 ww  . j a  v  a2  s . c o  m
     *  true:already in using  false:not using
     * @param port
     */
    public static boolean isLoclePortUsing(int port) {
        boolean flag = true;
        try {
            flag = isPortUsing("127.0.0.1", port);
        } catch (Exception e) {
        }
        return flag;
    }

    /***
     *  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;
    }
}

Related

  1. isLivereloadAvailable(int port)
  2. isLocalPortAvailable(final int port)
  3. isLocalPortFree(final int port)
  4. isLocalPortOccupied(int portNum)
  5. isLocalPortUsed(int port)
  6. isMulticastSupported(NetworkInterface pNif)
  7. isOpen(final int port)
  8. isPortActive(String host, int port)
  9. isPortAvailable(final int port)