option 0 now can close the program
All checks were successful
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/pr-etape5 This commit looks good
All checks were successful
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/pr-etape5 This commit looks good
This commit is contained in:
parent
f531547f2d
commit
2f924af9df
@ -3,19 +3,12 @@ package clientP2P;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
import java.util.List;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.net.UnknownHostException;
|
||||
import protocolP2P.RequestResponseCode;
|
||||
import protocolP2P.FileList;
|
||||
import protocolP2P.ProtocolP2PPacket;
|
||||
import protocolP2P.DiscoverRequest;
|
||||
import protocolP2P.DiscoverResponse;
|
||||
import protocolP2P.Payload;
|
||||
import protocolP2P.HashAlgorithm;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import localException.ProtocolError;
|
||||
import localException.InternalError;
|
||||
import localException.ProtocolError;
|
||||
@ -23,6 +16,13 @@ import localException.SizeError;
|
||||
import localException.TransmissionError;
|
||||
import localException.VersionError;
|
||||
import localException.SocketClosed;
|
||||
import protocolP2P.RequestResponseCode;
|
||||
import protocolP2P.FileList;
|
||||
import protocolP2P.ProtocolP2PPacket;
|
||||
import protocolP2P.DiscoverRequest;
|
||||
import protocolP2P.DiscoverResponse;
|
||||
import protocolP2P.Payload;
|
||||
import protocolP2P.HashAlgorithm;
|
||||
import remoteException.EmptyFile;
|
||||
import remoteException.EmptyDirectory;
|
||||
import remoteException.InternalRemoteError;
|
||||
@ -30,6 +30,7 @@ import remoteException.NotFound;
|
||||
import remoteException.ProtocolRemoteError;
|
||||
import remoteException.VersionRemoteError;
|
||||
import remoteException.NotATracker;
|
||||
import remoteException.UnknownHost;
|
||||
import tools.ServeErrors;
|
||||
import tools.HostItem;
|
||||
import tools.Logger;
|
||||
@ -228,60 +229,62 @@ public abstract class ClientManagement extends ServeErrors implements Runnable {
|
||||
/** Implementation of Runnable
|
||||
*/
|
||||
public void run() {
|
||||
try {
|
||||
int i = 1;
|
||||
String[] list = listDirectory();
|
||||
System.out.println("Files present on the server:");
|
||||
System.out.println("0 : Exit the program");
|
||||
for(String listItem: list) {
|
||||
System.out.println(i + " : " + listItem);
|
||||
i++;
|
||||
}
|
||||
System.out.println("Type the number associated with the file to download:");
|
||||
String f = scanner.nextLine();
|
||||
if(f.equals("0")){
|
||||
System.out.println("on ferme tout");
|
||||
}
|
||||
else{
|
||||
int j = Integer.parseInt(f);
|
||||
if(j <= list.length){
|
||||
j--;
|
||||
download(list[j]);
|
||||
System.out.println("File " + f + " sucessfully downloaded");
|
||||
writeLog("File " + f + " sucessfully downloaded", LogLevel.Info);
|
||||
boolean isrunning = true;
|
||||
while (isrunning){
|
||||
try {
|
||||
int i = 1;
|
||||
String[] list = listDirectory();
|
||||
System.out.println("Files present on the server:");
|
||||
System.out.println("0 : Exit the program");
|
||||
for(String listItem: list) {
|
||||
System.out.println(i + " : " + listItem);
|
||||
i++;
|
||||
}
|
||||
System.out.println("Type the number associated with the file to download:");
|
||||
String f = scanner.nextLine();
|
||||
if(f.equals("0")){
|
||||
isrunning = false;
|
||||
}
|
||||
else{
|
||||
System.out.println("File " + f + " unsucessfully downloaded, wrong number");
|
||||
writeLog("File " + f + " unsucessfully downloaded, wrong number", LogLevel.Info);
|
||||
int j = Integer.parseInt(f);
|
||||
if(j <= list.length){
|
||||
j--;
|
||||
download(list[j]);
|
||||
System.out.println("File " + f + " sucessfully downloaded");
|
||||
writeLog("File " + f + " sucessfully downloaded", LogLevel.Info);
|
||||
}
|
||||
else{
|
||||
System.out.println("File " + f + " unsucessfully downloaded, wrong number");
|
||||
writeLog("File " + f + " unsucessfully downloaded, wrong number", LogLevel.Info);
|
||||
}
|
||||
}
|
||||
} catch (EmptyDirectory e) {
|
||||
writeLog("Server has no file in directory", LogLevel.Error);
|
||||
} catch (InternalError e) {
|
||||
writeLog("Client internal error", LogLevel.Error);
|
||||
} catch (UnknownHostException e) {
|
||||
writeLog("Server host is unknown", LogLevel.Error);
|
||||
} catch (IOException e) {
|
||||
writeLog("Request cannot be send or response cannot be received", LogLevel.Error);
|
||||
} catch (TransmissionError e) {
|
||||
writeLog("Message received is too big", LogLevel.Error);
|
||||
} catch (ProtocolError e) {
|
||||
writeLog("Cannot decode server’s response", LogLevel.Error);
|
||||
} catch (VersionError e) {
|
||||
writeLog("Server’s response use bad version of the protocol", LogLevel.Error);
|
||||
} catch (SizeError e) {
|
||||
writeLog("Cannot handle this packets because of internal representation limitations of numbers on the client", LogLevel.Error);
|
||||
} catch (InternalRemoteError e) {
|
||||
writeLog("Server internal error", LogLevel.Error);
|
||||
} catch (ProtocolRemoteError e) {
|
||||
writeLog("Server cannot decode client’s request", LogLevel.Error);
|
||||
} catch (VersionRemoteError e) {
|
||||
writeLog("Server cannot decode this version of the protocol", LogLevel.Error);
|
||||
} catch (NotFound e) {
|
||||
writeLog("Server has not this file in directory", LogLevel.Error);
|
||||
} catch (EmptyFile e) {
|
||||
writeLog("File is empty", LogLevel.Error);
|
||||
}
|
||||
} catch (EmptyDirectory e) {
|
||||
writeLog("Server has no file in directory", LogLevel.Error);
|
||||
} catch (InternalError e) {
|
||||
writeLog("Client internal error", LogLevel.Error);
|
||||
} catch (UnknownHostException e) {
|
||||
writeLog("Server host is unknown", LogLevel.Error);
|
||||
} catch (IOException e) {
|
||||
writeLog("Request cannot be send or response cannot be received", LogLevel.Error);
|
||||
} catch (TransmissionError e) {
|
||||
writeLog("Message received is too big", LogLevel.Error);
|
||||
} catch (ProtocolError e) {
|
||||
writeLog("Cannot decode server’s response", LogLevel.Error);
|
||||
} catch (VersionError e) {
|
||||
writeLog("Server’s response use bad version of the protocol", LogLevel.Error);
|
||||
} catch (SizeError e) {
|
||||
writeLog("Cannot handle this packets because of internal representation limitations of numbers on the client", LogLevel.Error);
|
||||
} catch (InternalRemoteError e) {
|
||||
writeLog("Server internal error", LogLevel.Error);
|
||||
} catch (ProtocolRemoteError e) {
|
||||
writeLog("Server cannot decode client’s request", LogLevel.Error);
|
||||
} catch (VersionRemoteError e) {
|
||||
writeLog("Server cannot decode this version of the protocol", LogLevel.Error);
|
||||
} catch (NotFound e) {
|
||||
writeLog("Server has not this file in directory", LogLevel.Error);
|
||||
} catch (EmptyFile e) {
|
||||
writeLog("File is empty", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user