fixed closing of server, now at the END
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/pr-master This commit looks good Details

pull/108/head
js 5 years ago
parent d775ee7cbb
commit 7bd31a31c5

@ -25,6 +25,8 @@ import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.net.SocketException; import java.net.SocketException;
import javax.swing.JFrame; import javax.swing.JFrame;
import serverP2P.ServerManagementUDP;
import serverP2P.ServerManagementTCP;
/** Implementation of P2P-JAVA-PROJECT CLIENT interface for CLI /** Implementation of P2P-JAVA-PROJECT CLIENT interface for CLI
* @author Louis Royer * @author Louis Royer
@ -40,10 +42,15 @@ public class ClientInterfaceGUI extends ClientInterface {
*/ */
Logger loggerC; Logger loggerC;
private ServerManagementTCP smtcp;
private ServerManagementUDP smudp;
public ClientInterfaceGUI(ClientManagement clientManagement, Logger logger) {
public ClientInterfaceGUI(ClientManagement clientManagement, Logger logger, ServerManagementTCP smtcp, ServerManagementUDP smudp) {
super(clientManagement, logger); super(clientManagement, logger);
this.loggerC = logger; this.loggerC = logger;
this.smtcp = smtcp;
this.smudp = smudp;
} }
/** Implementation of Runnable /** Implementation of Runnable
@ -68,7 +75,7 @@ public class ClientInterfaceGUI extends ClientInterface {
win.setSize(550, 250); win.setSize(550, 250);
win.setLocationRelativeTo(null); win.setLocationRelativeTo(null);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.add(new DownloadSelectionGen(list, clientManagement, loggerC)); win.add(new DownloadSelectionGen(list, clientManagement, loggerC, smtcp, smudp));
win.setVisible(true); win.setVisible(true);
} catch (EmptyDirectory e) { } catch (EmptyDirectory e) {
writeLog("Server has no file in directory", LogLevel.Error); writeLog("Server has no file in directory", LogLevel.Error);

@ -109,7 +109,7 @@ public class ClientP2PGUI {
case "2" : case "2" :
System.out.println("Starting with UDP"); System.out.println("Starting with UDP");
ClientManagementUDP cmudp = new ClientManagementUDP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server); ClientManagementUDP cmudp = new ClientManagementUDP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server);
tclient = new Thread(new ClientInterfaceGUI(cmudp, loggerClient)); tclient = new Thread(new ClientInterfaceGUI(cmudp, loggerClient, smtcp, smudp));
break; break;
case "TCP": case "TCP":
case "tcp": case "tcp":
@ -117,7 +117,7 @@ public class ClientP2PGUI {
default: default:
System.out.println("Starting with TCP"); System.out.println("Starting with TCP");
ClientManagementTCP cmtcp = new ClientManagementTCP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server); ClientManagementTCP cmtcp = new ClientManagementTCP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server);
tclient = new Thread(new ClientInterfaceGUI(cmtcp, loggerClient)); tclient = new Thread(new ClientInterfaceGUI(cmtcp, loggerClient, smtcp, smudp));
break; break;
} }
tclient.setName("client P2P-JAVA-PROJECT GUI"); tclient.setName("client P2P-JAVA-PROJECT GUI");
@ -125,8 +125,8 @@ public class ClientP2PGUI {
try { try {
tclient.join(); tclient.join();
} catch (InterruptedException e) {} } catch (InterruptedException e) {}
smudp.setStop(); //smudp.setStop();
smtcp.setStop(); //smtcp.setStop();
} }

@ -26,26 +26,35 @@ import java.net.UnknownHostException;
import java.net.SocketException; import java.net.SocketException;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
import serverP2P.ServerManagementUDP;
import serverP2P.ServerManagementTCP;
public class DownloadFileGUI extends JPanel{ public class DownloadFileGUI extends JPanel{
private static final long serialVersionUID = 13L;
private String fileToDownload; private String fileToDownload;
private ClientManagement clientManagement; private ClientManagement clientManagement;
private Logger logger; private Logger logger;
private static final long serialVersionUID = 13L; private ServerManagementTCP smtcp;
private ServerManagementUDP smudp;
public DownloadFileGUI(String fileToDownload, ClientManagement clientManagement, Logger logger){ public DownloadFileGUI(String fileToDownload, ClientManagement clientManagement, Logger logger, ServerManagementTCP smtcp, ServerManagementUDP smudp){
this.fileToDownload = fileToDownload; this.fileToDownload = fileToDownload;
this.clientManagement = clientManagement; this.clientManagement = clientManagement;
this.logger = logger; this.logger = logger;
this.smtcp = smtcp;
this.smudp = smudp;
} }
public void download() { public void download() {
try { try {
System.out.println("Downloading " + fileToDownload + " ... "); System.out.println("Downloading " + fileToDownload + " ... ");
clientManagement.download(fileToDownload); clientManagement.download(fileToDownload);
smudp.setStop();
smtcp.setStop();
ErrorFrame erreur = new ErrorFrame("File " + fileToDownload + " sucessfully downloaded"); ErrorFrame erreur = new ErrorFrame("File " + fileToDownload + " sucessfully downloaded");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
ErrorFrame erreur = new ErrorFrame("File " + fileToDownload + " unsucessfully downloaded, wrong number"); ErrorFrame erreur = new ErrorFrame("File " + fileToDownload + " unsucessfully downloaded, wrong number");

@ -12,6 +12,8 @@ package gui;
import clientP2P.*; import clientP2P.*;
import tools.LogLevel; import tools.LogLevel;
import tools.Logger; import tools.Logger;
import serverP2P.ServerManagementUDP;
import serverP2P.ServerManagementTCP;
/** /**
* @author Louis Royer * @author Louis Royer
@ -30,6 +32,9 @@ public class DownloadSelectionGen extends javax.swing.JPanel {
private String[] listFilesToDownload; private String[] listFilesToDownload;
private ClientManagement clientManagement; private ClientManagement clientManagement;
private Logger logger; private Logger logger;
private ServerManagementTCP smtcp;
private ServerManagementUDP smudp;
/** /**
* @param listFilesToDownload list of files to display * @param listFilesToDownload list of files to display
@ -37,10 +42,12 @@ public class DownloadSelectionGen extends javax.swing.JPanel {
* @param logger logger * @param logger logger
* Creates new form ArgumentsGen * Creates new form ArgumentsGen
*/ */
public DownloadSelectionGen(String[] listFilesToDownload, ClientManagement clientManagement, Logger logger) { public DownloadSelectionGen(String[] listFilesToDownload, ClientManagement clientManagement, Logger logger, ServerManagementTCP smtcp, ServerManagementUDP smudp) {
this.listFilesToDownload = listFilesToDownload; this.listFilesToDownload = listFilesToDownload;
this.clientManagement = clientManagement; this.clientManagement = clientManagement;
this.logger = logger; this.logger = logger;
this.smtcp = smtcp;
this.smudp = smudp;
initComponents(); initComponents();
} }
@ -121,7 +128,7 @@ public class DownloadSelectionGen extends javax.swing.JPanel {
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String fileSelected = jList1.getSelectedValue(); String fileSelected = jList1.getSelectedValue();
System.out.println("File to download: " + fileSelected); System.out.println("File to download: " + fileSelected);
DownloadFileGUI dl = new DownloadFileGUI(fileSelected, clientManagement, logger); DownloadFileGUI dl = new DownloadFileGUI(fileSelected, clientManagement, logger, smtcp, smudp);
dl.download(); dl.download();
} }

Loading…
Cancel
Save