Java HTTP Port Find available(final int port)

Here you can find the source of available(final int port)

Description

available

License

Open Source License

Declaration

private static boolean available(final int port) 

Method Source Code

//package com.java2s;
/*//from   w  ww  . j a v a 2s  .c  o m
 * [y] hybris Platform
 *
 * Copyright (c) 2000-2014 hybris AG
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of hybris
 * ("Confidential Information"). You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the
 * license agreement you entered into with hybris.
 *
 *  
 */

import java.io.IOException;

import java.net.ServerSocket;

public class Main {
    private static boolean available(final int port) {
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(port);
            serverSocket.setReuseAddress(true);
            return true;
        } catch (final IOException e) {
            //
        } finally {
            if (serverSocket != null) {
                try {
                    serverSocket.close();
                } catch (final IOException e) {
                    /* should not be thrown */
                }
            }
        }
        return false;
    }
}

Related

  1. available(int port)
  2. available(int port)
  3. available(int port)
  4. available(int port)