public enum NetworkUtil extends Enum<NetworkUtil>
This class includes methods to interact with network resources, such as finding an available port.
| Modifier and Type | Method and Description |
|---|---|
static int |
getAvailablePort()
Retrieves an available port number on the local machine.
|
static NetworkUtil |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static NetworkUtil[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static NetworkUtil[] values()
for (NetworkUtil c : NetworkUtil.values()) System.out.println(c);
public static NetworkUtil valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic static int getAvailablePort()
This method attempts to bind to an automatically allocated port, then returns the port number. It provides a simple way to find a port that's very likely to be available.
RuntimeException - if an IOException occurs while trying to create a ServerSocketCopyright © 2023. All rights reserved.