From 1ec120c373e48d7070eb0ef78dd16d9276b710b3 Mon Sep 17 00:00:00 2001 From: js Date: Mon, 2 Mar 2020 15:16:21 +0100 Subject: [PATCH] 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; + } + +}