| | |
| | | /** |
| | | * Returns {@code true} if the provided port is free and we can use it, |
| | | * {@code false} otherwise. |
| | | * @param hostname the host name we are analyzing. |
| | | * @param port the port we are analyzing. |
| | | * @return {@code true} if the provided port is free and we can use it, |
| | | * {@code false} otherwise. |
| | | */ |
| | | public static boolean canUseAsPort(int port) |
| | | public static boolean canUseAsPort(String hostname, int port) |
| | | { |
| | | boolean canUseAsPort = false; |
| | | ServerSocket serverSocket = null; |
| | | try |
| | | { |
| | | InetSocketAddress socketAddress = new InetSocketAddress(port); |
| | | InetSocketAddress socketAddress = new InetSocketAddress(hostname, port); |
| | | serverSocket = new ServerSocket(); |
| | | if (!isWindows()) |
| | | { |
| | |
| | | */ |
| | | try |
| | | { |
| | | new Socket("localhost", port); |
| | | new Socket(hostname, port); |
| | | canUseAsPort = false; |
| | | |
| | | } catch (IOException ioe) |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns {@code true} if the provided port is free and we can use it, |
| | | * {@code false} otherwise. |
| | | * @param port the port we are analyzing. |
| | | * @return {@code true} if the provided port is free and we can use it, |
| | | * {@code false} otherwise. |
| | | */ |
| | | public static boolean canUseAsPort(int port) |
| | | { |
| | | return canUseAsPort("localhost", port); |
| | | } |
| | | |
| | | /** |
| | | * Returns {@code true} if the provided port is a priviledged port, |
| | | * {@code false} otherwise. |
| | | * @param port the port we are analyzing. |