fixed a lot of things
This commit is contained in:
parent
b87b3c70ef
commit
20a444cb9b
@ -161,15 +161,19 @@ public class ArgumentsGen extends javax.swing.JPanel {
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
String hostnameServer = jTextField2.getText();
|
||||
String portServer = jTextField1.getText();
|
||||
String portServerStr = jTextField1.getText();
|
||||
String hostnameTracker = jTextField3.getText();
|
||||
String portTracker = jTextField4.getText();
|
||||
String portTrackerStr = jTextField4.getText();
|
||||
String protocolClient = jComboBox1.getSelectedItem().toString();
|
||||
System.out.println("hostnameServer: " + hostnameServer);
|
||||
System.out.println("portServer: " + portServer);
|
||||
System.out.println("portServer: " + portServerStr);
|
||||
System.out.println("hostnameTracker: " + hostnameTracker);
|
||||
System.out.println("portTracker: " + portTracker);
|
||||
System.out.println("portTracker: " + portTrackerStr);
|
||||
System.out.println("protocol: " + protocolClient);
|
||||
int portServer = Integer.parseInt(portServerStr);
|
||||
int portTracker = Integer.parseInt(portTrackerStr);
|
||||
ClientP2Pgui c = new ClientP2Pgui(hostnameServer, portServer, hostnameTracker, portTracker, protocolClient);
|
||||
c.connect();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import clientP2P.ClientManagement;
|
||||
import tools.SearchFile;
|
||||
import tools.LogLevel;
|
||||
import tools.Logger;
|
||||
import java.util.Scanner;
|
||||
import localException.ProtocolError;
|
||||
import localException.InternalError;
|
||||
import localException.ProtocolError;
|
||||
@ -33,17 +32,19 @@ import javax.swing.JFrame;
|
||||
* @author JS Auge
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ClientInterfaceCLI extends ClientInterface {
|
||||
private Scanner scanner;
|
||||
public class ClientInterfaceGUI extends ClientInterface {
|
||||
|
||||
/** Constructor with clientManagement, logger and scanner.
|
||||
* @param clientManagement ClientManagement used
|
||||
* @param logger Logger used
|
||||
* @param scanner Scanner used to read input
|
||||
*/
|
||||
public ClientInterfaceGUI(ClientManagement clientManagement, Logger logger, Scanner scanner) {
|
||||
|
||||
Logger loggerC;
|
||||
|
||||
public ClientInterfaceGUI(ClientManagement clientManagement, Logger logger) {
|
||||
super(clientManagement, logger);
|
||||
this.scanner = scanner;
|
||||
this.loggerC = logger;
|
||||
}
|
||||
|
||||
/** Implementation of Runnable
|
||||
@ -53,20 +54,42 @@ public class ClientInterfaceCLI extends ClientInterface {
|
||||
public void run(){
|
||||
boolean isRunning = initHostList();
|
||||
if (isRunning) {
|
||||
try {
|
||||
try{
|
||||
int i = 1;
|
||||
SearchFile searchEngine = new SearchFile();
|
||||
int optionSearch = 0;
|
||||
String searchInput = "";
|
||||
String[] list = clientManagement.listDirectory();
|
||||
//String[] resultArray = {};
|
||||
|
||||
|
||||
|
||||
MainWindow win = new MainWindow();
|
||||
win.add(new DownloadSelectionGen(list, clientManagement, logger, scanner));
|
||||
win.add(new DownloadSelectionGen(list, clientManagement, loggerC));
|
||||
} 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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Initialization of hostList with retry in failure
|
||||
@ -79,11 +102,7 @@ public class ClientInterfaceCLI extends ClientInterface {
|
||||
while (!contacted && !stop) {
|
||||
try {
|
||||
if (!firstLoop) {
|
||||
writeLog("Cannot contact tracker. Try again [Y/n] ?", LogLevel.Error);
|
||||
String tryAgain = scanner.nextLine();
|
||||
if (tryAgain.equals("n") || tryAgain.equals("N")) {
|
||||
stop = true;
|
||||
}
|
||||
writeLog("Cannot contact tracker... ", LogLevel.Error);
|
||||
}
|
||||
firstLoop = false;
|
||||
clientManagement.initHostList();
|
||||
@ -97,4 +116,6 @@ public class ClientInterfaceCLI extends ClientInterface {
|
||||
}
|
||||
return !stop;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -21,7 +21,7 @@ import tools.TrackerPortRange;
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class ClientP2P {
|
||||
public class ClientP2Pgui {
|
||||
private String logDir = "logs/";
|
||||
private String partsDir = ".parts/";
|
||||
private Logger loggerServer;
|
||||
@ -55,26 +55,29 @@ public class ClientP2P {
|
||||
* @param hostnameTracker hostname of tracker
|
||||
* @param portTracker port of tracker
|
||||
*/
|
||||
public ClientP2P(String hostnameServer, int portServer, String hostnameTracker, int portTracker, String protocolP2P) {
|
||||
public ClientP2Pgui(String hostnameServer, int portServer, String hostnameTracker, int portTracker, String protocolP2P) {
|
||||
|
||||
if (directories == null && loggerServer == null && loggerClient == null) {
|
||||
directories = new Directories("P2P_JAVA_PROJECT_" + server.getPort());
|
||||
directories.createSubdir(logDir);
|
||||
loggerServer = new Logger(directories.getDataHomeDirectory() + logDir + "server.log", DEBUG);
|
||||
loggerClient = new Logger(directories.getDataHomeDirectory() + logDir + "client.log", DEBUG);
|
||||
directories.createSubdir(partsDir);
|
||||
}
|
||||
|
||||
this.hostnameServer = hostnameServer;
|
||||
this.hostnameTracker = hostnameTracker;
|
||||
this.portServer = portServer;
|
||||
this.portTracker = portTracker;
|
||||
this.protocolP2P = protocolP2P;
|
||||
|
||||
final ServerPortRange serverPortRange = new ServerPortRange();
|
||||
final TrackerPortRange trackerPortRange = new TrackerPortRange();
|
||||
|
||||
if (!serverPortRange.isPortInRange(portServer)){
|
||||
ErrorFrame erreur = new ErrorFrame("SERVER: Port not in range. ");
|
||||
}
|
||||
|
||||
if (!trackerPortRange.isPortInRange(portTracker)){
|
||||
ErrorFrame erreur = new ErrorFrame("TRACKER: Port not in range");
|
||||
}
|
||||
|
||||
|
||||
server = new HostItem(hostnameServer, portServer);
|
||||
tracker = new HostItem(hostnameTracker, portTracker);
|
||||
initDirectoriesAndLoggers();
|
||||
@ -106,14 +109,14 @@ public class ClientP2P {
|
||||
}
|
||||
|
||||
Thread tclient;
|
||||
switch (protocolClient) {
|
||||
switch (protocolP2P) {
|
||||
case "UDP":
|
||||
case "udp":
|
||||
case "upd": // to avoid users typos
|
||||
case "2" :
|
||||
System.out.println("Starting with UDP");
|
||||
ClientManagementUDP cmudp = new ClientManagementUDP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server);
|
||||
tclient = new Thread(new ClientInterfaceCLI(cmudp, loggerClient));
|
||||
tclient = new Thread(new ClientInterfaceGUI(cmudp, loggerClient));
|
||||
break;
|
||||
case "TCP":
|
||||
case "tcp":
|
||||
@ -121,10 +124,10 @@ public class ClientP2P {
|
||||
default:
|
||||
System.out.println("Starting with TCP");
|
||||
ClientManagementTCP cmtcp = new ClientManagementTCP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server);
|
||||
tclient = new Thread(new ClientInterfaceCLI(cmtcp, loggerClient));
|
||||
tclient = new Thread(new ClientInterfaceGUI(cmtcp, loggerClient));
|
||||
break;
|
||||
}
|
||||
tclient.setName("client P2P-JAVA-PROJECT");
|
||||
tclient.setName("client P2P-JAVA-PROJECT GUI");
|
||||
tclient.start();
|
||||
try {
|
||||
tclient.join();
|
||||
|
@ -6,7 +6,6 @@ import clientP2P.ClientManagement;
|
||||
import tools.SearchFile;
|
||||
import tools.LogLevel;
|
||||
import tools.Logger;
|
||||
import java.util.Scanner;
|
||||
import localException.ProtocolError;
|
||||
import localException.InternalError;
|
||||
import localException.ProtocolError;
|
||||
@ -26,32 +25,27 @@ import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.SocketException;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class DownloadFileGUI extends JPanel{
|
||||
|
||||
private String fileToDownload;
|
||||
private ClientManagement clientManagement;
|
||||
private Logger logger;
|
||||
private Scanner scanner;
|
||||
|
||||
public DownloadFileGUI(String fileToDownload, ClientManagement clientManagement, Logger logger, Scanner scanner){
|
||||
public DownloadFileGUI(String fileToDownload, ClientManagement clientManagement, Logger logger){
|
||||
this.fileToDownload = fileToDownload;
|
||||
this.clientManagement = clientManagement;
|
||||
this.logger = logger;
|
||||
this.scanner = scanner;
|
||||
}
|
||||
|
||||
public void download(){
|
||||
try {
|
||||
clientManagement.download(fileToDownload);
|
||||
|
||||
ErrorFrame erreur = new ErrorFrame("File " + f + " sucessfully downloaded");
|
||||
} else {
|
||||
|
||||
ErrorFrame erreur = new ErrorFrame("File " + f + " unsucessfully downloaded, wrong number");
|
||||
}
|
||||
ErrorFrame erreur = new ErrorFrame("File " + fileToDownload + " sucessfully downloaded");
|
||||
} catch (NumberFormatException e) {
|
||||
ErrorFrame erreur = new ErrorFrame("File " + f + " unsucessfully downloaded, wrong number"),
|
||||
ErrorFrame erreur = new ErrorFrame("File " + fileToDownload + " unsucessfully downloaded, wrong number");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@ package gui;
|
||||
import clientP2P.*;
|
||||
import tools.LogLevel;
|
||||
import tools.Logger;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* @author Louis Royer
|
||||
@ -30,18 +29,16 @@ public class DownloadSelectionGen extends javax.swing.JPanel {
|
||||
private static final long serialVersionUID = 13L;
|
||||
private String[] listFilesToDownload;
|
||||
private ClientManagement clientManagement;
|
||||
private Scanner scanner;
|
||||
private Logger logger;
|
||||
// End of variables declaration
|
||||
|
||||
/**
|
||||
* Creates new form ArgumentsGen
|
||||
*/
|
||||
public DownloadSelectionGen(String[] listFilesToDownload, ClientManagement clientManagement, Logger logger, Scanner scanner) {
|
||||
public DownloadSelectionGen(String[] listFilesToDownload, ClientManagement clientManagement, Logger logger) {
|
||||
this.listFilesToDownload = listFilesToDownload;
|
||||
this.clientManagement = clientManagement;
|
||||
this.logger = logger;
|
||||
this.scanner = scanner;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
@ -121,8 +118,9 @@ public class DownloadSelectionGen extends javax.swing.JPanel {
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
String fileSelected = jList1.getSelectedValue();
|
||||
DownloadFileGUI interface = new DownloadFileGUI(fileSelected, clientManagement, logger, scanner);
|
||||
DownloadFileGUI.download();
|
||||
System.out.println("File to download: " + fileSelected);
|
||||
//DownloadFileGUI interface = new DownloadFileGUI(fileSelected, clientManagement, logger, scanner);
|
||||
//DownloadFileGUI.download();
|
||||
}
|
||||
|
||||
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
|
@ -17,7 +17,7 @@ public class MainWindow extends JFrame{
|
||||
// "fichier2", "fichier3", "fichier4"};
|
||||
//fenetre.add(new DownloadSelectionGen(listTest));
|
||||
fenetre.setVisible(true);
|
||||
ErrorFrame erreur = new ErrorFrame("ceci est une erreur");
|
||||
//ErrorFrame erreur = new ErrorFrame("ceci est une erreur");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user