added help argument

This commit is contained in:
Flavien Haas 2020-03-20 15:57:09 +01:00
parent 8d8ed294e8
commit cfc24354b9

View File

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