programs quit when ports entered are wrong #97
@ -132,68 +132,63 @@ public class ClientP2P {
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("using hostname : " + hostnameServer);
|
||||
if(serverPortRange.isPortInRange(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);
|
||||
if (serverPortRange.isPortInRange(portServer)){
|
||||
if(trackerPortRange.isPortInRange(portTracker)){
|
||||
System.out.println("using hostname : " + hostnameServer);
|
||||
System.out.println("using port : " + portServer);
|
||||
System.out.println("tracker hostname : " + hostnameTracker);
|
||||
System.out.println("tracker port : " + portTracker);
|
||||
ClientP2P c = new ClientP2P(hostnameServer, portServer, hostnameTracker, portTracker);
|
||||
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);
|
||||
Thread tudp = new Thread(smudp);
|
||||
tudp.setName("server UDP P2P-JAVA-PROJECT");
|
||||
tudp.start();
|
||||
Thread ttcp = new Thread(smtcp);
|
||||
ttcp.setName("server TCP P2P-JAVA-PROJECT");
|
||||
ttcp.start();
|
||||
|
||||
if(trackerPortRange.isPortInRange(portTracker)){
|
||||
System.out.println("using port : " + portTracker);
|
||||
}
|
||||
else {
|
||||
System.out.println("Port not in range. " + trackerPortRange);
|
||||
portTracker = trackerPortRange.getDefaultPort();
|
||||
}
|
||||
// Wait a bit before printing client interface
|
||||
// This is not required, but allow to have a cleaner interface
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch(InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
ClientP2P c = new ClientP2P(hostnameServer, portServer, hostnameTracker, portTracker);
|
||||
|
||||
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);
|
||||
Thread tudp = new Thread(smudp);
|
||||
tudp.setName("server UDP P2P-JAVA-PROJECT");
|
||||
tudp.start();
|
||||
Thread ttcp = new Thread(smtcp);
|
||||
ttcp.setName("server TCP P2P-JAVA-PROJECT");
|
||||
ttcp.start();
|
||||
|
||||
// Wait a bit before printing client interface
|
||||
// This is not required, but allow to have a cleaner interface
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch(InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
Thread tclient;
|
||||
switch(protocolClient){
|
||||
case "UDP":
|
||||
case "udp":
|
||||
case "upd": // to avoid users typos
|
||||
case "2" :
|
||||
System.out.println("Starting with UDP");
|
||||
ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.tracker, c.directories.getDataHomeDirectory() + c.partsDir, c.loggerClient, c.scanner, c.server);
|
||||
tclient = new Thread(cmudp);
|
||||
break;
|
||||
case "TCP":
|
||||
case "tcp":
|
||||
case "1":
|
||||
default:
|
||||
System.out.println("Starting with TCP");
|
||||
ClientManagementTCP cmtcp = new ClientManagementTCP(c.directories.getDataHomeDirectory(), c.tracker, c.directories.getDataHomeDirectory() + c.partsDir, c.loggerClient, c.scanner, c.server);
|
||||
tclient = new Thread(cmtcp);
|
||||
break;
|
||||
}
|
||||
tclient.setName("client P2P-JAVA-PROJECT");
|
||||
tclient.start();
|
||||
try {
|
||||
tclient.join();
|
||||
} catch (InterruptedException e) {}
|
||||
smudp.setStop();
|
||||
smtcp.setStop();
|
||||
}
|
||||
else{
|
||||
System.out.println("\n TRACKER: Port not in range. " + trackerPortRange);
|
||||
}
|
||||
}
|
||||
|
||||
Thread tclient;
|
||||
switch(protocolClient){
|
||||
case "UDP":
|
||||
case "udp":
|
||||
case "upd": // to avoid users typos
|
||||
case "2" :
|
||||
System.out.println("Starting with UDP");
|
||||
ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.tracker, c.directories.getDataHomeDirectory() + c.partsDir, c.loggerClient, c.scanner, c.server);
|
||||
tclient = new Thread(cmudp);
|
||||
break;
|
||||
case "TCP":
|
||||
case "tcp":
|
||||
case "1":
|
||||
default:
|
||||
System.out.println("Starting with TCP");
|
||||
ClientManagementTCP cmtcp = new ClientManagementTCP(c.directories.getDataHomeDirectory(), c.tracker, c.directories.getDataHomeDirectory() + c.partsDir, c.loggerClient, c.scanner, c.server);
|
||||
tclient = new Thread(cmtcp);
|
||||
break;
|
||||
else{
|
||||
System.out.println("\n SERVER: Port not in range. " + serverPortRange);
|
||||
}
|
||||
tclient.setName("client P2P-JAVA-PROJECT");
|
||||
tclient.start();
|
||||
try {
|
||||
tclient.join();
|
||||
} catch (InterruptedException e) {}
|
||||
smudp.setStop();
|
||||
smtcp.setStop();
|
||||
}
|
||||
}
|
||||
|
@ -90,39 +90,35 @@ public class ServerP2P {
|
||||
System.out.println("enter tracker's port (default = " + trackerPortRange.getDefaultPort() + "): ");
|
||||
String portTrackerStr = scanner.nextLine();
|
||||
if(portTrackerStr.equals("")){
|
||||
portTracker = serverPortRange.getDefaultPort();
|
||||
portTracker = trackerPortRange.getDefaultPort();
|
||||
System.out.println("using default port : " + portTracker);
|
||||
} else {
|
||||
portTracker = Integer.valueOf(Integer.parseInt(portTrackerStr));
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("using hostname : " + hostnameServer);
|
||||
if(serverPortRange.isPortInRange(portServer)) {
|
||||
System.out.println("using port : " + portServer);
|
||||
if (serverPortRange.isPortInRange(portServer)){
|
||||
if(trackerPortRange.isPortInRange(portTracker)){
|
||||
System.out.println("using hostname : " + hostnameServer);
|
||||
System.out.println("using port : " + portServer);
|
||||
System.out.println("tracker hostname : " + hostnameTracker);
|
||||
System.out.println("tracker port : " + portTracker);
|
||||
ServerP2P s = new ServerP2P(hostnameServer, portServer, hostnameTracker, portTracker);
|
||||
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);
|
||||
Thread tudp = new Thread(smudp);
|
||||
tudp.setName("server UDP P2P-JAVA-PROJECT");
|
||||
tudp.start();
|
||||
Thread ttcp = new Thread(smtcp);
|
||||
ttcp.setName("server TCP P2P-JAVA-PROJECT");
|
||||
ttcp.start();
|
||||
}
|
||||
else{
|
||||
System.out.println("\n TRACKER: Port not in range. " + trackerPortRange);
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.out.println("Port not in range. " + serverPortRange);
|
||||
portServer = serverPortRange.getDefaultPort();
|
||||
else{
|
||||
System.out.println("\n SERVER: Port not in range. " + serverPortRange);
|
||||
}
|
||||
System.out.println("tracker hostname : " + hostnameTracker);
|
||||
|
||||
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);
|
||||
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);
|
||||
Thread tudp = new Thread(smudp);
|
||||
tudp.setName("server UDP P2P-JAVA-PROJECT");
|
||||
tudp.start();
|
||||
Thread ttcp = new Thread(smtcp);
|
||||
ttcp.setName("server TCP P2P-JAVA-PROJECT");
|
||||
ttcp.start();
|
||||
}
|
||||
}
|
||||
|
@ -75,19 +75,17 @@ public class Tracker {
|
||||
if(trackerPortRange.isPortInRange(port)) {
|
||||
System.out.println("using port : " + port);
|
||||
t = new Tracker(hostname, port);
|
||||
TrackerManagementUDP tmudp = new TrackerManagementUDP(t.tracker, t.logger);
|
||||
TrackerManagementTCP tmtcp = new TrackerManagementTCP(t.tracker, t.logger);
|
||||
Thread tudp = new Thread(tmudp);
|
||||
tudp.setName("Tracker UDP P2P-JAVA-PROJECT");
|
||||
tudp.start();
|
||||
Thread ttcp = new Thread(tmtcp);
|
||||
ttcp.setName("Tracker TCP P2P-JAVA-PROJECT");
|
||||
ttcp.start();
|
||||
}
|
||||
else {
|
||||
System.out.println("Port not in range. " + trackerPortRange);
|
||||
t = new Tracker(hostname, trackerPortRange.getDefaultPort());
|
||||
}
|
||||
|
||||
TrackerManagementUDP tmudp = new TrackerManagementUDP(t.tracker, t.logger);
|
||||
TrackerManagementTCP tmtcp = new TrackerManagementTCP(t.tracker, t.logger);
|
||||
Thread tudp = new Thread(tmudp);
|
||||
tudp.setName("Tracker UDP P2P-JAVA-PROJECT");
|
||||
tudp.start();
|
||||
Thread ttcp = new Thread(tmtcp);
|
||||
ttcp.setName("Tracker TCP P2P-JAVA-PROJECT");
|
||||
ttcp.start();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user