return testport in method
This commit is contained in:
parent
d4bcff6f8c
commit
702fb399c3
@ -1,5 +1,7 @@
|
||||
package tools;
|
||||
|
||||
import javafx.util.Pair;
|
||||
|
||||
/** Test ports.
|
||||
* @author Louis Royer
|
||||
* @author Flavien Haas
|
||||
@ -8,18 +10,19 @@ package tools;
|
||||
*/
|
||||
public class TestPort {
|
||||
|
||||
public boolean testPortServer(int port) {
|
||||
public boolean testPortServer(int port, String message) {
|
||||
if((port > 7000) && (port < 7999)){
|
||||
return true;
|
||||
}
|
||||
message = message + "Wrong port (7000 -> 7999), using default port 7070";
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean testPortTracker(int port) {
|
||||
public Pair<Integer,String> testPortTracker(int port) {
|
||||
if((port > 6000) && (port < 6999)){
|
||||
return true;
|
||||
return new Pair<>(0,"");
|
||||
}
|
||||
return false;
|
||||
return new Pair<>(1, "Wrong port (6000 -> 6999), using default port 6969");
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package tracker;
|
||||
|
||||
import java.util.Scanner;
|
||||
import javafx.util.Pair;
|
||||
import tracker.TrackerManagementTCP;
|
||||
import tracker.TrackerManagementUDP;
|
||||
import tools.Directories;
|
||||
@ -42,7 +43,7 @@ public class Tracker {
|
||||
final String defaultPort = "6969";
|
||||
final String defaultHostname = "localhost";
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
TestPort testPortTracker = new TestPort();
|
||||
TestPort testPort = new TestPort();
|
||||
String hostname;
|
||||
String port;
|
||||
Tracker t;
|
||||
@ -73,14 +74,15 @@ public class Tracker {
|
||||
}
|
||||
|
||||
System.out.println("using hostname : " + hostname);
|
||||
if(testPortTracker.testPortTracker(Integer.parseInt(port))){
|
||||
Pair<Integer, String> PtestPortTracker = testPort.testPortTracker(Integer.parseInt(port));
|
||||
if(PtestPortTracker.getKey() == 0){
|
||||
System.out.println("using port : " + port);
|
||||
t = new Tracker(port);
|
||||
}
|
||||
else {
|
||||
System.out.println("Wrong port (6000 -> 6999), using default port 6969");
|
||||
System.out.println(PtestPortTracker.getValue());
|
||||
t = new Tracker(defaultPort);
|
||||
t.logger.write("Wrong port (6000 -> 6999), using default port 6969", LogLevel.Warning);
|
||||
t.logger.write(PtestPortTracker.getValue(), LogLevel.Warning);
|
||||
}
|
||||
|
||||
TrackerManagementUDP tmudp = new TrackerManagementUDP(hostname, t.port, t.logger);
|
||||
|
Loading…
Reference in New Issue
Block a user