|
|
@ -128,7 +128,7 @@ public abstract class ClientManagement extends ServeErrors implements Runnable {
|
|
|
|
hostList = ((DiscoverResponse)p).getHostList();
|
|
|
|
hostList = ((DiscoverResponse)p).getHostList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closeTrackerSocket();
|
|
|
|
closeTrackerSocket();
|
|
|
|
} catch (SocketClosed e){
|
|
|
|
} catch (SocketClosed e) {
|
|
|
|
writeLog("listDirectory : SocketClosed", LogLevel.Error);
|
|
|
|
writeLog("listDirectory : SocketClosed", LogLevel.Error);
|
|
|
|
throw new ProtocolError();
|
|
|
|
throw new ProtocolError();
|
|
|
|
} catch (NotATracker e) {
|
|
|
|
} catch (NotATracker e) {
|
|
|
@ -202,7 +202,7 @@ public abstract class ClientManagement extends ServeErrors implements Runnable {
|
|
|
|
} catch (EmptyFile e) {
|
|
|
|
} catch (EmptyFile e) {
|
|
|
|
writeLog(e, LogLevel.Error);
|
|
|
|
writeLog(e, LogLevel.Error);
|
|
|
|
throw new ProtocolError();
|
|
|
|
throw new ProtocolError();
|
|
|
|
} catch (SocketClosed e){
|
|
|
|
} catch (SocketClosed e) {
|
|
|
|
writeLog("listDirectory : SocketClosed", LogLevel.Error);
|
|
|
|
writeLog("listDirectory : SocketClosed", LogLevel.Error);
|
|
|
|
throw new ProtocolError();
|
|
|
|
throw new ProtocolError();
|
|
|
|
} catch (NotATracker e) {
|
|
|
|
} catch (NotATracker e) {
|
|
|
@ -271,33 +271,36 @@ public abstract class ClientManagement extends ServeErrors implements Runnable {
|
|
|
|
/** Implementation of Runnable
|
|
|
|
/** Implementation of Runnable
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
boolean isrunning = true;
|
|
|
|
boolean isRunning = true;
|
|
|
|
while (isrunning){
|
|
|
|
while (isRunning) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int i = 1;
|
|
|
|
int i = 1;
|
|
|
|
String[] list = listDirectory();
|
|
|
|
String[] list = listDirectory();
|
|
|
|
System.out.println("Files present on the server:");
|
|
|
|
System.out.println("Files present on the server:");
|
|
|
|
System.out.println("0 : Exit the program");
|
|
|
|
System.out.println("R: Refresh file list");
|
|
|
|
|
|
|
|
System.out.println("0: Exit the program");
|
|
|
|
for(String listItem: list) {
|
|
|
|
for(String listItem: list) {
|
|
|
|
System.out.println(i + " : " + listItem);
|
|
|
|
System.out.println(i + ": " + listItem);
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.println("Type the number associated with the file to download:");
|
|
|
|
System.out.println("Type the number associated with the file to download:");
|
|
|
|
String f = scanner.nextLine();
|
|
|
|
String f = scanner.nextLine();
|
|
|
|
if(f.equals("0")){
|
|
|
|
if (f.equals("0")) {
|
|
|
|
isrunning = false;
|
|
|
|
isRunning = false;
|
|
|
|
}
|
|
|
|
} else if (f.equals("R") || f.equals("r")) {
|
|
|
|
else{
|
|
|
|
writeLog("File list refresh.", LogLevel.Info);
|
|
|
|
int j = Integer.parseInt(f);
|
|
|
|
} else {
|
|
|
|
if(j <= list.length){
|
|
|
|
try {
|
|
|
|
j--;
|
|
|
|
int j = Integer.parseInt(f);
|
|
|
|
download(list[j]);
|
|
|
|
if (j <= list.length) {
|
|
|
|
System.out.println("File " + f + " sucessfully downloaded");
|
|
|
|
j--;
|
|
|
|
writeLog("File " + f + " sucessfully downloaded", LogLevel.Info);
|
|
|
|
download(list[j]);
|
|
|
|
}
|
|
|
|
writeLog("File " + f + " sucessfully downloaded", LogLevel.Info);
|
|
|
|
else{
|
|
|
|
} else {
|
|
|
|
System.out.println("File " + f + " unsucessfully downloaded, wrong number");
|
|
|
|
writeLog("File " + f + " unsucessfully downloaded, wrong number", LogLevel.Error);
|
|
|
|
writeLog("File " + f + " unsucessfully downloaded, wrong number", LogLevel.Info);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
|
|
writeLog("File " + f + " unsucessfully downloaded, wrong number", LogLevel.Error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (EmptyDirectory e) {
|
|
|
|
} catch (EmptyDirectory e) {
|
|
|
|