|
|
|
@ -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(trackerPortRange.isPortInRange(portTracker)){
|
|
|
|
|
System.out.println("using port : " + portTracker);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
System.out.println("Port not in range. " + trackerPortRange);
|
|
|
|
|
portTracker = trackerPortRange.getDefaultPort();
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
ClientP2P c = new ClientP2P(hostnameServer, portServer, hostnameTracker, portTracker);
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|