Lock server port between 1024 and 64000

This commit is contained in:
Arnaud Vergnet 2021-01-31 22:47:55 +01:00
parent b281b4b530
commit ada6167c25

View file

@ -32,11 +32,16 @@ public class Main {
}
private static int getPort(String value, int defaultValue) {
int port = defaultValue;
int port;
try {
port = Integer.parseInt(value.trim());
if (port <= 1024 || port >= 64000) {
System.out.println("Port should be between 1024 and 64000. Falling back to default.");
port = defaultValue;
}
} catch (NumberFormatException e) {
System.out.println("Could not read port " + value + ". Using default.");
System.out.println("Could not read port " + value + ". Falling back to default.");
port = defaultValue;
}
return port;
}