|
|
@ -71,57 +71,63 @@ public class ClientP2P {
|
|
|
|
* @param args server listenning port
|
|
|
|
* @param args server listenning port
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static void main(String [] args) {
|
|
|
|
public static void main(String [] args) {
|
|
|
|
ClientP2P c;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (args[1].equals("help") || args[1].equals("-h") || args[1].equals("h")){
|
|
|
|
c = new ClientP2P(args[1]);
|
|
|
|
System.out.println("usage : java -ea clientP2P.ClientP2P -- <PORT> ");
|
|
|
|
} catch (IndexOutOfBoundsException e){
|
|
|
|
|
|
|
|
c = new ClientP2P("" + defaultPort);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
ClientP2P c;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
c = new ClientP2P(args[1]);
|
|
|
|
|
|
|
|
} catch (IndexOutOfBoundsException e){
|
|
|
|
|
|
|
|
c = new ClientP2P("" + defaultPort);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Server threads
|
|
|
|
// Server threads
|
|
|
|
ServerManagementUDP smudp = new ServerManagementUDP(c.directories.getDataHomeDirectory() + subdir, c.port, c.loggerServer);
|
|
|
|
ServerManagementUDP smudp = new ServerManagementUDP(c.directories.getDataHomeDirectory() + subdir, c.port, c.loggerServer);
|
|
|
|
ServerManagementTCP smtcp = new ServerManagementTCP(c.directories.getDataHomeDirectory() + subdir, c.port, c.loggerServer);
|
|
|
|
ServerManagementTCP smtcp = new ServerManagementTCP(c.directories.getDataHomeDirectory() + subdir, c.port, c.loggerServer);
|
|
|
|
Thread tudp = new Thread(smudp);
|
|
|
|
Thread tudp = new Thread(smudp);
|
|
|
|
tudp.setName("server UDP P2P-JAVA-PROJECT (port: " + c.port + ")");
|
|
|
|
tudp.setName("server UDP P2P-JAVA-PROJECT (port: " + c.port + ")");
|
|
|
|
tudp.start();
|
|
|
|
tudp.start();
|
|
|
|
Thread ttcp = new Thread(smtcp);
|
|
|
|
Thread ttcp = new Thread(smtcp);
|
|
|
|
ttcp.setName("server TCP P2P-JAVA-PROJECT (port: " + c.port + ")");
|
|
|
|
ttcp.setName("server TCP P2P-JAVA-PROJECT (port: " + c.port + ")");
|
|
|
|
ttcp.start();
|
|
|
|
ttcp.start();
|
|
|
|
|
|
|
|
|
|
|
|
// Wait a bit before printing client interface
|
|
|
|
// Wait a bit before printing client interface
|
|
|
|
// This is not required, but allow to have a cleaner interface
|
|
|
|
// This is not required, but allow to have a cleaner interface
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Thread.sleep(100);
|
|
|
|
Thread.sleep(100);
|
|
|
|
} catch(InterruptedException e) {
|
|
|
|
} catch(InterruptedException e) {
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// initialize Host lists
|
|
|
|
// initialize Host lists
|
|
|
|
c.hostList = HostList.getServList();
|
|
|
|
c.hostList = HostList.getServList();
|
|
|
|
System.out.println("Client : Which transport protocol do you want to use? [TCP/udp]");
|
|
|
|
System.out.println("Client : Which transport protocol do you want to use? [TCP/udp]");
|
|
|
|
Scanner sc = new Scanner(System.in);
|
|
|
|
Scanner sc = new Scanner(System.in);
|
|
|
|
String transportchoosen = sc.nextLine();
|
|
|
|
String transportchoosen = sc.nextLine();
|
|
|
|
Thread t;
|
|
|
|
Thread t;
|
|
|
|
switch(transportchoosen){
|
|
|
|
switch(transportchoosen){
|
|
|
|
case "UDP":
|
|
|
|
case "UDP":
|
|
|
|
case "udp":
|
|
|
|
case "udp":
|
|
|
|
case "upd": // alias typo
|
|
|
|
case "upd": // alias typo
|
|
|
|
case "2" :
|
|
|
|
case "2" :
|
|
|
|
System.out.println("Starting with UDP");
|
|
|
|
System.out.println("Starting with UDP");
|
|
|
|
ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.hostList, c.directories.getDataHomeDirectory() + c.parts + "/", c.loggerClient);
|
|
|
|
ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.hostList, c.directories.getDataHomeDirectory() + c.parts + "/", c.loggerClient);
|
|
|
|
t = new Thread(cmudp);
|
|
|
|
t = new Thread(cmudp);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "TCP":
|
|
|
|
case "TCP":
|
|
|
|
case "tcp":
|
|
|
|
case "tcp":
|
|
|
|
case "1":
|
|
|
|
case "1":
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
System.out.println("Starting with TCP");
|
|
|
|
System.out.println("Starting with TCP");
|
|
|
|
ClientManagementTCP cmtcp = new ClientManagementTCP(c.directories.getDataHomeDirectory(), c.hostList, c.directories.getDataHomeDirectory() + c.parts + "/", c.loggerClient);
|
|
|
|
ClientManagementTCP cmtcp = new ClientManagementTCP(c.directories.getDataHomeDirectory(), c.hostList, c.directories.getDataHomeDirectory() + c.parts + "/", c.loggerClient);
|
|
|
|
t = new Thread(cmtcp);
|
|
|
|
t = new Thread(cmtcp);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
t.setName("client P2P-JAVA-PROJECT");
|
|
|
|
t.setName("client P2P-JAVA-PROJECT");
|
|
|
|
t.start();
|
|
|
|
t.start();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|