magic number fix
This commit is contained in:
parent
f800bfeec4
commit
1da7f416d4
1 changed files with 4 additions and 2 deletions
|
|
@ -6,6 +6,8 @@ import java.util.Scanner;
|
||||||
|
|
||||||
public class PortChecker {
|
public class PortChecker {
|
||||||
private static final int defaultPort = 8080;
|
private static final int defaultPort = 8080;
|
||||||
|
private static final int lastValidPort = 65535;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a free port to launch the program on.
|
* Finds a free port to launch the program on.
|
||||||
|
|
@ -23,7 +25,7 @@ public class PortChecker {
|
||||||
while(true){
|
while(true){
|
||||||
int port = portScanner.nextInt();
|
int port = portScanner.nextInt();
|
||||||
|
|
||||||
if(port > 0 && port <=65535){ //range of valid ports
|
if(port > 0 && port <=lastValidPort){ //range of valid ports
|
||||||
isPortAvailable(port);
|
isPortAvailable(port);
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +33,7 @@ public class PortChecker {
|
||||||
System.out.println("Try a different port:");
|
System.out.println("Try a different port:");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a port is actually available.
|
* Checks whether a port is actually available.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue