add tools to get server list

This commit is contained in:
js 2020-03-02 15:16:21 +01:00 committed by Louis
parent bc6b94b6a6
commit 1ec120c373
2 changed files with 31 additions and 1 deletions

View File

@ -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");

29
src/tools/HostList.java Normal file
View File

@ -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;
}
}