From cfc24354b9866137c929d2b9e18a694f971d865a Mon Sep 17 00:00:00 2001 From: flavien Date: Fri, 20 Mar 2020 15:57:09 +0100 Subject: [PATCH 1/2] added help argument --- src/clientP2P/ClientP2P.java | 100 +++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/src/clientP2P/ClientP2P.java b/src/clientP2P/ClientP2P.java index 2d56fd8..34a9519 100644 --- a/src/clientP2P/ClientP2P.java +++ b/src/clientP2P/ClientP2P.java @@ -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 -- "); } + 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; - } + // 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(); + t.setName("client P2P-JAVA-PROJECT"); + t.start(); + } } } From 879164304a17d15c856d0d4750236a64c823f756 Mon Sep 17 00:00:00 2001 From: flavien Date: Fri, 20 Mar 2020 16:39:27 +0100 Subject: [PATCH 2/2] added server help argument --- src/serverP2P/ServerP2P.java | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/serverP2P/ServerP2P.java b/src/serverP2P/ServerP2P.java index 313d263..be8bfec 100644 --- a/src/serverP2P/ServerP2P.java +++ b/src/serverP2P/ServerP2P.java @@ -35,15 +35,21 @@ public class ServerP2P { * @param args parameters */ public static void main(String [] args) { - ServerP2P s = new ServerP2P(args[1]); - ServerManagementUDP smudp = new ServerManagementUDP(s.directories.getDataHomeDirectory() + subdir, s.port, s.logger); - ServerManagementTCP smtcp = new ServerManagementTCP(s.directories.getDataHomeDirectory() + subdir, s.port, 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(); + + if (args[1].equals("help") || args[1].equals("-h") || args[1].equals("h")){ + System.out.println("usage : java -ea serveurP2P.ServeurP2P -- "); + } + else{ + ServerP2P s = new ServerP2P(args[1]); + ServerManagementUDP smudp = new ServerManagementUDP(s.directories.getDataHomeDirectory() + subdir, s.port, s.logger); + ServerManagementTCP smtcp = new ServerManagementTCP(s.directories.getDataHomeDirectory() + subdir, s.port, 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(); + } } }