io.polyglotted.applauncher.util.Ports Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of app-launcher Show documentation
Show all versions of app-launcher Show documentation
Launch an in-process application
The newest version!
package io.polyglotted.applauncher.util;
import lombok.SneakyThrows;
import java.net.ServerSocket;
import java.util.Optional;
public abstract class Ports {
public static int randomPort() {
return allocate(Optional.empty());
}
@SneakyThrows
public static int allocate(Optional port) {
try (ServerSocket socket = new ServerSocket(port.orElse(0))) {
socket.setReuseAddress(true);
return socket.getLocalPort();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy