Lock server port between 1024 and 64000
This commit is contained in:
parent
b281b4b530
commit
ada6167c25
1 changed files with 7 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue