programs quit when ports entered are wrong
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/pr-master This commit looks good Details

pull/97/head
Flavien Haas 5 years ago
parent 2cc2868450
commit e4f637f317

@ -132,26 +132,13 @@ public class ClientP2P {
} }
} }
System.out.println("using hostname : " + hostnameServer);
if (serverPortRange.isPortInRange(portServer)){ if (serverPortRange.isPortInRange(portServer)){
if(trackerPortRange.isPortInRange(portTracker)){
System.out.println("using hostname : " + hostnameServer);
System.out.println("using port : " + portServer); System.out.println("using port : " + portServer);
}
else {
System.out.println("Port not in range. " + serverPortRange);
portServer = serverPortRange.getDefaultPort();
}
System.out.println("tracker hostname : " + hostnameTracker); System.out.println("tracker hostname : " + hostnameTracker);
System.out.println("tracker port : " + portTracker);
if(trackerPortRange.isPortInRange(portTracker)){
System.out.println("using port : " + portTracker);
}
else {
System.out.println("Port not in range. " + trackerPortRange);
portTracker = trackerPortRange.getDefaultPort();
}
ClientP2P c = new ClientP2P(hostnameServer, portServer, hostnameTracker, portTracker); ClientP2P c = new ClientP2P(hostnameServer, portServer, hostnameTracker, portTracker);
ServerManagementUDP smudp = new ServerManagementUDP(c.directories.getDataHomeDirectory(), c.server, c.tracker, c.loggerServer); ServerManagementUDP smudp = new ServerManagementUDP(c.directories.getDataHomeDirectory(), c.server, c.tracker, c.loggerServer);
ServerManagementTCP smtcp = new ServerManagementTCP(c.directories.getDataHomeDirectory(), c.server, c.tracker, c.loggerServer); ServerManagementTCP smtcp = new ServerManagementTCP(c.directories.getDataHomeDirectory(), c.server, c.tracker, c.loggerServer);
Thread tudp = new Thread(smudp); Thread tudp = new Thread(smudp);
@ -196,4 +183,12 @@ public class ClientP2P {
smudp.setStop(); smudp.setStop();
smtcp.setStop(); smtcp.setStop();
} }
else{
System.out.println("\n TRACKER: Port not in range. " + trackerPortRange);
}
}
else{
System.out.println("\n SERVER: Port not in range. " + serverPortRange);
}
}
} }

@ -90,31 +90,19 @@ public class ServerP2P {
System.out.println("enter tracker's port (default = " + trackerPortRange.getDefaultPort() + "): "); System.out.println("enter tracker's port (default = " + trackerPortRange.getDefaultPort() + "): ");
String portTrackerStr = scanner.nextLine(); String portTrackerStr = scanner.nextLine();
if(portTrackerStr.equals("")){ if(portTrackerStr.equals("")){
portTracker = serverPortRange.getDefaultPort(); portTracker = trackerPortRange.getDefaultPort();
System.out.println("using default port : " + portTracker); System.out.println("using default port : " + portTracker);
} else { } else {
portTracker = Integer.valueOf(Integer.parseInt(portTrackerStr)); portTracker = Integer.valueOf(Integer.parseInt(portTrackerStr));
} }
} }
System.out.println("using hostname : " + hostnameServer);
if (serverPortRange.isPortInRange(portServer)){ if (serverPortRange.isPortInRange(portServer)){
if(trackerPortRange.isPortInRange(portTracker)){
System.out.println("using hostname : " + hostnameServer);
System.out.println("using port : " + portServer); System.out.println("using port : " + portServer);
}
else {
System.out.println("Port not in range. " + serverPortRange);
portServer = serverPortRange.getDefaultPort();
}
System.out.println("tracker hostname : " + hostnameTracker); System.out.println("tracker hostname : " + hostnameTracker);
System.out.println("tracker port : " + portTracker);
if(trackerPortRange.isPortInRange(portTracker)) {
System.out.println("using port : " + portTracker);
}
else {
System.out.println("Port not in range. " + trackerPortRange);
portTracker = trackerPortRange.getDefaultPort();
}
ServerP2P s = new ServerP2P(hostnameServer, portServer, hostnameTracker, portTracker); ServerP2P s = new ServerP2P(hostnameServer, portServer, hostnameTracker, portTracker);
ServerManagementUDP smudp = new ServerManagementUDP(s.directories.getDataHomeDirectory() + subdir, s.server, s.tracker, s.logger); ServerManagementUDP smudp = new ServerManagementUDP(s.directories.getDataHomeDirectory() + subdir, s.server, s.tracker, s.logger);
ServerManagementTCP smtcp = new ServerManagementTCP(s.directories.getDataHomeDirectory() + subdir, s.server, s.tracker, s.logger); ServerManagementTCP smtcp = new ServerManagementTCP(s.directories.getDataHomeDirectory() + subdir, s.server, s.tracker, s.logger);
@ -125,4 +113,12 @@ public class ServerP2P {
ttcp.setName("server TCP P2P-JAVA-PROJECT"); ttcp.setName("server TCP P2P-JAVA-PROJECT");
ttcp.start(); ttcp.start();
} }
else{
System.out.println("\n TRACKER: Port not in range. " + trackerPortRange);
}
}
else{
System.out.println("\n SERVER: Port not in range. " + serverPortRange);
}
}
} }

@ -75,12 +75,6 @@ public class Tracker {
if(trackerPortRange.isPortInRange(port)) { if(trackerPortRange.isPortInRange(port)) {
System.out.println("using port : " + port); System.out.println("using port : " + port);
t = new Tracker(hostname, port); t = new Tracker(hostname, port);
}
else {
System.out.println("Port not in range. " + trackerPortRange);
t = new Tracker(hostname, trackerPortRange.getDefaultPort());
}
TrackerManagementUDP tmudp = new TrackerManagementUDP(t.tracker, t.logger); TrackerManagementUDP tmudp = new TrackerManagementUDP(t.tracker, t.logger);
TrackerManagementTCP tmtcp = new TrackerManagementTCP(t.tracker, t.logger); TrackerManagementTCP tmtcp = new TrackerManagementTCP(t.tracker, t.logger);
Thread tudp = new Thread(tmudp); Thread tudp = new Thread(tmudp);
@ -90,4 +84,8 @@ public class Tracker {
ttcp.setName("Tracker TCP P2P-JAVA-PROJECT"); ttcp.setName("Tracker TCP P2P-JAVA-PROJECT");
ttcp.start(); ttcp.start();
} }
else {
System.out.println("Port not in range. " + trackerPortRange);
}
}
} }

Loading…
Cancel
Save