@ -1,11 +1,21 @@
package clientP2P ;
package clientP2P ;
import tools.HostItem ;
import tools.Logger ;
import java.util.Arrays ;
import tools.LogLevel ;
import java.util.Scanner ;
import java.util.Scanner ;
import java.util.List ;
import java.util.List ;
import java.io.IOException ;
import java.nio.file.Files ;
import java.nio.file.Paths ;
import java.net.UnknownHostException ;
import java.security.MessageDigest ;
import java.security.NoSuchAlgorithmException ;
import localException.ProtocolError ;
import localException.ProtocolError ;
import tools.ServeErrors ;
import localException.InternalError ;
import localException.ProtocolError ;
import localException.SizeError ;
import localException.TransmissionError ;
import localException.VersionError ;
import localException.SocketClosed ;
import protocolP2P.RequestResponseCode ;
import protocolP2P.RequestResponseCode ;
import protocolP2P.FileList ;
import protocolP2P.FileList ;
import protocolP2P.ProtocolP2PPacket ;
import protocolP2P.ProtocolP2PPacket ;
@ -13,12 +23,6 @@ import protocolP2P.DiscoverRequest;
import protocolP2P.DiscoverResponse ;
import protocolP2P.DiscoverResponse ;
import protocolP2P.Payload ;
import protocolP2P.Payload ;
import protocolP2P.HashAlgorithm ;
import protocolP2P.HashAlgorithm ;
import localException.InternalError ;
import localException.ProtocolError ;
import localException.SizeError ;
import localException.TransmissionError ;
import localException.VersionError ;
import localException.SocketClosed ;
import remoteException.EmptyFile ;
import remoteException.EmptyFile ;
import remoteException.EmptyDirectory ;
import remoteException.EmptyDirectory ;
import remoteException.InternalRemoteError ;
import remoteException.InternalRemoteError ;
@ -27,14 +31,10 @@ import remoteException.ProtocolRemoteError;
import remoteException.VersionRemoteError ;
import remoteException.VersionRemoteError ;
import remoteException.NotATracker ;
import remoteException.NotATracker ;
import remoteException.UnknownHost ;
import remoteException.UnknownHost ;
import java.io.IOException ;
import tools.ServeErrors ;
import java.security.MessageDigest ;
import tools.HostItem ;
import java.security.NoSuchAlgorithmException ;
import tools.Logger ;
import java.net.UnknownHostException ;
import tools.LogLevel ;
import java.nio.file.Files ;
import java.nio.file.Paths ;
import java.util.Arrays ;
/ * * Implementation of P2P - JAVA - PROJECT CLIENT
/ * * Implementation of P2P - JAVA - PROJECT CLIENT
* @author Louis Royer
* @author Louis Royer
@ -229,17 +229,35 @@ public abstract class ClientManagement extends ServeErrors implements Runnable {
/ * * Implementation of Runnable
/ * * Implementation of Runnable
* /
* /
public void run ( ) {
public void run ( ) {
boolean isrunning = true ;
while ( isrunning ) {
try {
try {
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" ) ;
for ( String listItem : list ) {
for ( String listItem : list ) {
System . out . println ( listItem ) ;
System . out . println ( i + " : " + listItem ) ;
i + + ;
}
}
System . out . println ( " Name of the file to download:") ;
System . out . println ( " Type the number associated with the file to download:") ;
String f = scanner . nextLine ( ) ;
String f = scanner . nextLine ( ) ;
download ( f ) ;
if ( f . equals ( "0" ) ) {
isrunning = false ;
}
else {
int j = Integer . parseInt ( f ) ;
if ( j < = list . length ) {
j - - ;
download ( list [ j ] ) ;
System . out . println ( "File " + f + " sucessfully downloaded" ) ;
System . out . println ( "File " + f + " sucessfully downloaded" ) ;
writeLog ( "File " + f + " sucessfully downloaded" , LogLevel . Info ) ;
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 ) {
} catch ( EmptyDirectory e ) {
writeLog ( "Server has no file in directory" , LogLevel . Error ) ;
writeLog ( "Server has no file in directory" , LogLevel . Error ) ;
} catch ( InternalError e ) {
} catch ( InternalError e ) {
@ -268,5 +286,5 @@ public abstract class ClientManagement extends ServeErrors implements Runnable {
writeLog ( "File is empty" , LogLevel . Error ) ;
writeLog ( "File is empty" , LogLevel . Error ) ;
}
}
}
}
}
}
}