Minestom/src/main/java/net/minestom/server/utils/NetworkUtils.java

30 lines
548 B
Java
Raw Normal View History

2021-04-25 23:41:13 +02:00
package net.minestom.server.utils;
import java.io.IOException;
import java.net.ServerSocket;
/**
* Network related utilities.
*/
public class NetworkUtils {
private NetworkUtils() { }
/**
* Gets a free port.
*
* @return the port
* @throws IOException if a port could not be found
*/
public static int getFreePort() throws IOException {
int port;
final ServerSocket socket = new ServerSocket(0);
port = socket.getLocalPort();
socket.close();
return port;
}
}