Browse Source

Lock server port between 1024 and 64000

Arnaud Vergnet 3 years ago
parent
commit
ada6167c25
1 changed files with 7 additions and 2 deletions
  1. 7
    2
      server/src/main/java/fr/insa/clavardator/server/Main.java

+ 7
- 2
server/src/main/java/fr/insa/clavardator/server/Main.java View File

@@ -32,11 +32,16 @@ public class Main {
32 32
 	}
33 33
 
34 34
 	private static int getPort(String value, int defaultValue) {
35
-		int port = defaultValue;
35
+		int port;
36 36
 		try {
37 37
 			port = Integer.parseInt(value.trim());
38
+			if (port <= 1024 || port >= 64000) {
39
+				System.out.println("Port should be between 1024 and 64000. Falling back to default.");
40
+				port = defaultValue;
41
+			}
38 42
 		} catch (NumberFormatException e) {
39
-			System.out.println("Could not read port " + value + ". Using default.");
43
+			System.out.println("Could not read port " + value + ". Falling back to default.");
44
+			port = defaultValue;
40 45
 		}
41 46
 		return port;
42 47
 	}

Loading…
Cancel
Save