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.SocketException;
import javax.swing.JFrame;
import serverP2P.ServerManagementUDP;
import serverP2P.ServerManagementTCP;
/** Implementation of P2P-JAVA-PROJECT CLIENT interface for CLI
* @author Louis Royer
@ -40,10 +42,15 @@ public class ClientInterfaceGUI extends ClientInterface {
*/
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);
this.loggerC = logger;
this.smtcp = smtcp;
this.smudp = smudp;
}
/** Implementation of Runnable
@ -68,7 +75,7 @@ public class ClientInterfaceGUI extends ClientInterface {
win.setSize(550, 250);
win.setLocationRelativeTo(null);
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);
} catch (EmptyDirectory e) {
writeLog("Server has no file in directory", LogLevel.Error);

@ -109,7 +109,7 @@ public class ClientP2PGUI {
case "2" :
System.out.println("Starting with UDP");
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;
case "TCP":
case "tcp":
@ -117,7 +117,7 @@ public class ClientP2PGUI {
default:
System.out.println("Starting with TCP");
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;
}
tclient.setName("client P2P-JAVA-PROJECT GUI");
@ -125,8 +125,8 @@ public class ClientP2PGUI {
try {
tclient.join();
} catch (InterruptedException e) {}
smudp.setStop();
smtcp.setStop();
//smudp.setStop();
//smtcp.setStop();
}

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

@ -12,6 +12,8 @@ package gui;
import clientP2P.*;
import tools.LogLevel;
import tools.Logger;
import serverP2P.ServerManagementUDP;
import serverP2P.ServerManagementTCP;
/**
* @author Louis Royer
@ -30,6 +32,9 @@ public class DownloadSelectionGen extends javax.swing.JPanel {
private String[] listFilesToDownload;
private ClientManagement clientManagement;
private Logger logger;
private ServerManagementTCP smtcp;
private ServerManagementUDP smudp;
/**
* @param listFilesToDownload list of files to display
@ -37,10 +42,12 @@ public class DownloadSelectionGen extends javax.swing.JPanel {
* @param logger logger
* 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.clientManagement = clientManagement;
this.logger = logger;
this.smtcp = smtcp;
this.smudp = smudp;
initComponents();
}
@ -121,7 +128,7 @@ public class DownloadSelectionGen extends javax.swing.JPanel {
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String fileSelected = jList1.getSelectedValue();
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();
}

Loading…
Cancel
Save