From 424af597803b6c66c4fb083f084afef876e89351 Mon Sep 17 00:00:00 2001 From: js Date: Mon, 2 Mar 2020 15:16:21 +0100 Subject: [PATCH 1/5] add tools to get server list --- src/clientP2P/ClientManagementUDP.java | 3 ++- src/tools/HostList.java | 29 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/tools/HostList.java diff --git a/src/clientP2P/ClientManagementUDP.java b/src/clientP2P/ClientManagementUDP.java index 83b3d7b..9a25b3a 100644 --- a/src/clientP2P/ClientManagementUDP.java +++ b/src/clientP2P/ClientManagementUDP.java @@ -72,13 +72,14 @@ public class ClientManagementUDP implements Runnable { */ public void run() { try { + System.out.println("Enter all servers: type \"stop\" when finished"); + Scanner scanner = new Scanner(System.in); String[] list = listDirectory(); System.out.println("Files present on the server:"); for(String listItem: list) { System.out.println(listItem); } System.out.println("Name of the file to download:"); - Scanner scanner = new Scanner(System.in); String f = scanner.nextLine(); download(f); System.out.println("File sucessfully downloaded"); diff --git a/src/tools/HostList.java b/src/tools/HostList.java new file mode 100644 index 0000000..0d8ea59 --- /dev/null +++ b/src/tools/HostList.java @@ -0,0 +1,29 @@ +package tools; + +import java.util.Scanner; + +public class HostList{ + /** Helper to get the server list from the user + * @author Louis Royer + * @author Flavien Haas + * @author JS Auge + * @version 1.0 + */ + + public String[] getServList(){ + String[] serverList = new String[20]; + Scanner scanner = new Scanner(System.in); + String servName = ""; + int i = 0; + do { + System.out.println("Name of the next server:"); + servName = scanner.nextLine(); + if (servName != "stop"){ + serverList[i] = servName; + } + ++i; + } while (servName != "stop"); + return serverList; + } + +} -- 2.30.2 From 78deb16e41cb1f4c2282a6e4e77ae45a96f82f3d Mon Sep 17 00:00:00 2001 From: js Date: Tue, 3 Mar 2020 08:48:21 +0100 Subject: [PATCH 2/5] replace the String[] with an arrayList (servList) --- src/tools/HostList.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/tools/HostList.java b/src/tools/HostList.java index 0d8ea59..4acaf92 100644 --- a/src/tools/HostList.java +++ b/src/tools/HostList.java @@ -1,6 +1,11 @@ package tools; import java.util.Scanner; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.ListIterator; + public class HostList{ /** Helper to get the server list from the user @@ -10,18 +15,21 @@ public class HostList{ * @version 1.0 */ - public String[] getServList(){ - String[] serverList = new String[20]; +/** +* Let the user enter all server and puts it in a list +* @return list of servers +*/ + + public List getServList(){ + List serverList = new ArrayList(); Scanner scanner = new Scanner(System.in); String servName = ""; - int i = 0; do { System.out.println("Name of the next server:"); servName = scanner.nextLine(); if (servName != "stop"){ - serverList[i] = servName; + serverList.add(servName); } - ++i; } while (servName != "stop"); return serverList; } -- 2.30.2 From 9fa68b9e988d9f8b35b600b5dfda9498406ddde8 Mon Sep 17 00:00:00 2001 From: js Date: Tue, 3 Mar 2020 19:47:21 +0100 Subject: [PATCH 3/5] multiple servers impl (does not work yet) --- src/clientP2P/ClientP2P.java | 24 +++++++++++++++++++++--- src/tools/HostList.java | 4 ++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/clientP2P/ClientP2P.java b/src/clientP2P/ClientP2P.java index c8ee8a9..89594be 100644 --- a/src/clientP2P/ClientP2P.java +++ b/src/clientP2P/ClientP2P.java @@ -1,16 +1,25 @@ package clientP2P; import clientP2P.ClientManagementUDP; import clientP2P.ClientManagementTCP; +import tools.HostList; import tools.Directories; import java.util.Scanner; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.ListIterator; public class ClientP2P { private String host; private int port; private Directories directories; + private List hostList; + private HostList tool = new HostList(); + public ClientP2P() { directories = new Directories("P2P_JAVA_PROJECT_CLIENT"); host = "localhost"; + hostList = tool.getServList(); port = 40001; System.out.println("Client will try to contact server at " + host + " on port " + port + ". It will save files in " + directories.getDataHomeDirectory()); directories.askOpenDataHomeDirectory(null); @@ -27,8 +36,18 @@ public class ClientP2P { case "udp": case "2" : System.out.println("Starting with UDP"); - ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.host, c.port); - t = new Thread(cmudp); + /* ListIterator it = c.hostList.listIterator(); + do { + String str = it.next(); + ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), str, c.port); + t = new Thread(cmudp); + } while (it.hasNext()); + */ + for (String str : c.hostList){ + ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), str, c.port); + t = new Thread(cmudp); + } + //ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.host, c.port); break; case "TCP": case "tcp": @@ -39,7 +58,6 @@ public class ClientP2P { t = new Thread(cmtcp); break; } - t.setName("client P2P-JAVA-PROJECT"); t.start(); } diff --git a/src/tools/HostList.java b/src/tools/HostList.java index 4acaf92..979cbe9 100644 --- a/src/tools/HostList.java +++ b/src/tools/HostList.java @@ -17,7 +17,7 @@ public class HostList{ /** * Let the user enter all server and puts it in a list -* @return list of servers +* @return list of servers */ public List getServList(){ @@ -25,7 +25,7 @@ public class HostList{ Scanner scanner = new Scanner(System.in); String servName = ""; do { - System.out.println("Name of the next server:"); + System.out.println("Name of the next server: (or \"stop\" when finished)"); servName = scanner.nextLine(); if (servName != "stop"){ serverList.add(servName); -- 2.30.2 From ddaedfcf923a977ba6546b97fb028288dcecfdd4 Mon Sep 17 00:00:00 2001 From: js Date: Tue, 3 Mar 2020 20:04:02 +0100 Subject: [PATCH 4/5] problem with threads and multiple servers --- src/clientP2P/ClientP2P.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/clientP2P/ClientP2P.java b/src/clientP2P/ClientP2P.java index 89594be..57effd2 100644 --- a/src/clientP2P/ClientP2P.java +++ b/src/clientP2P/ClientP2P.java @@ -46,6 +46,10 @@ public class ClientP2P { for (String str : c.hostList){ ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), str, c.port); t = new Thread(cmudp); + /** + t.setName("client P2P-JAVA-PROJECT"); + t.start(); + */ } //ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.host, c.port); break; -- 2.30.2 From e3882b8d5542059445b4888d9157e731e0fd342d Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 10 Mar 2020 23:50:02 +0100 Subject: [PATCH 5/5] Fix jenkins .jar created files --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3097b04..644d8db 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,10 +7,10 @@ sh 'javac -cp "./src" -d "./bin" $(find . -iname "*.java" -type f) -Xlint:deprecation -encoding UTF8' sh 'echo "BUILDING CLIENT"' sh 'echo Main-Class: clientP2P/ClientP2P > MANIFEST.MF' - sh 'jar -cvmf MANIFEST.MF client.jar $(find . \\( -iname "*.class" -and ! -iwholename "*/clientP2P/*.class" \\) -type f)' + sh 'jar -cvmf MANIFEST.MF client.jar $(find . \\( -iname "*.class" -and ! -iwholename "*/serverP2P/*.class" \\) -type f)' sh 'echo "BUILDING SERVER"' sh 'echo Main-Class: javaProjet2020/Server > MANIFEST.MF' - sh 'jar -cvmf MANIFEST.MF server.jar $(find . \\( -iname "*.class" -and ! -iwholename "*/serverP2P/*.class" \\) -type f)' + sh 'jar -cvmf MANIFEST.MF server.jar $(find . \\( -iname "*.class" -and ! -iwholename "*/clientP2P/*.class" \\) -type f)' sh 'tar -zcvf sources.tar.gz src/' } } -- 2.30.2