retrieve support for agurments

pull/63/head
Flavien Haas 5 years ago
parent d0eff567f5
commit d4bcff6f8c

@ -1,28 +0,0 @@
package tools;
/** Test if IP are legitimate.
* @author Louis Royer
* @author Flavien Haas
* @author JS Auge
* @version 1.0
*/
public class TestLegitIP {
public boolean TestIP(String hostname) {
if(hostname.equals("localhost")){
return true;
}
else{
String[] ipArray = hostname.split("\\.");
if(ipArray.length != 4){
return false;
}
for(int i= 0; i < ipArray.length; i++){
if((Integer.parseInt(ipArray[i]) > 255) || (Integer.parseInt(ipArray[i]) < 0)){
return false;
}
}
}
return true;
}
}

@ -7,7 +7,6 @@ import tools.Directories;
import tools.Logger;
import tools.LogLevel;
import tools.TestPort;
import tools.TestLegitIP;
/** Tracker implementation
* First argument of main method is port listened by the tracker, and is mandatory.
@ -43,29 +42,39 @@ public class Tracker {
final String defaultPort = "6969";
final String defaultHostname = "localhost";
Scanner scanner = new Scanner(System.in);
TestLegitIP testLegitIP = new TestLegitIP();
TestPort testPortTracker = new TestPort();
String hostname;
String port;
Tracker t;
do{
System.out.println("args.lenght : " + args.length);
if ((args.length != 3) && (args.length != 0)){
System.out.println("usage : java tracker.Tracker or java trackerP2P.trackerP2P -- <hostname> <PORT> (default localhost:6969, range 6000 -> 6999)");
}
else{
if(args.length == 3){
hostname = args[1];
port = args[2];
}
else{
System.out.println("Tracker Server, enter hostname to bind (default = localhost): ");
String hostname = scanner.nextLine();
hostname = scanner.nextLine();
if(hostname.equals("")){
hostname = defaultHostname;
System.out.println("using default hostname : " + hostname);
}
} while (!testLegitIP.TestIP(hostname))
System.out.println("using hostname : " + hostname);
System.out.println("enter port (default = 6969): ");
String port = scanner.nextLine();
port = scanner.nextLine();
if(port.equals("")){
port = defaultPort;
System.out.println("using default port : " + port);
} else {
System.out.println("using port : " + port);
}
}
System.out.println("using hostname : " + hostname);
if(testPortTracker.testPortTracker(Integer.parseInt(port))){
System.out.println("using port : " + port);
t = new Tracker(port);
}
else {
@ -83,4 +92,5 @@ public class Tracker {
ttcp.setName("Tracker TCP P2P-JAVA-PROJECT");
ttcp.start();
}
}
}

Loading…
Cancel
Save