Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider d61cd63b rédigé par Youness's avatar Youness
Parcourir les fichiers

Modification code

parent 2368bdc8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 243 ajouts et 197 suppressions
/.metadata/
/lry/
/mainVeto.class
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
package lry.dip.tcp; package lry.dip.tcp;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
...@@ -10,6 +10,8 @@ import lry.dip.tcp.Echantillon; ...@@ -10,6 +10,8 @@ import lry.dip.tcp.Echantillon;
public class ClientSocketTCP { public class ClientSocketTCP {
/***** Attributs *****/
private Inet4Address IPServeur; private Inet4Address IPServeur;
private int portServeur; private int portServeur;
private ObjectOutputStream fluxSortie; private ObjectOutputStream fluxSortie;
...@@ -20,9 +22,14 @@ public class ClientSocketTCP { ...@@ -20,9 +22,14 @@ public class ClientSocketTCP {
private String ligne; private String ligne;
private PrintWriter ecrire; private PrintWriter ecrire;
private int PortClient = 0; private int PortClient = 0;
/*****Constructeur*****/
public ClientSocketTCP() {} public ClientSocketTCP() {
}
/*****Mthodes*****/
public void connecter(int pPort, String pIP) { public void connecter(int pPort, String pIP) {
System.out.println("Connexion au serveur : " + pIP + " /" + pPort); System.out.println("Connexion au serveur : " + pIP + " /" + pPort);
this.portServeur = pPort; this.portServeur = pPort;
...@@ -61,7 +68,7 @@ public class ClientSocketTCP { ...@@ -61,7 +68,7 @@ public class ClientSocketTCP {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void envoyerEchantillon(Echantillon e) { public void envoyerEchantillon(Echantillon e) {
System.out.println("Envoi de l'chantillon."); System.out.println("Envoi de l'chantillon.");
try { try {
...@@ -71,17 +78,15 @@ public class ClientSocketTCP { ...@@ -71,17 +78,15 @@ public class ClientSocketTCP {
IOex.printStackTrace(); IOex.printStackTrace();
} }
} }
public Echantillon recevoirRequete() { public Echantillon recevoirRequete() {
while (true) { while (true) {
try { try {
Echantillon e = (Echantillon) this.fluxEntree.readObject(); Echantillon e = (Echantillon) this.fluxEntree.readObject();
if(e.getNom().equals("suppression")) { if (e.getNom().equals("suppression")) {
System.out.println("Recevoir requete : Suppression"); System.out.println("Recevoir requete : Suppression");
return e; return e;
} } else {
else {
System.out.println("Recevoir requete : Insertion"); System.out.println("Recevoir requete : Insertion");
return e; return e;
} }
......
...@@ -3,8 +3,10 @@ package lry.dip.tcp; ...@@ -3,8 +3,10 @@ package lry.dip.tcp;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
public class Echantillon implements Serializable{ public class Echantillon implements Serializable {
/***** Attributs *****/
private int id; private int id;
private String nom; private String nom;
private String espece; private String espece;
...@@ -12,16 +14,18 @@ public class Echantillon implements Serializable{ ...@@ -12,16 +14,18 @@ public class Echantillon implements Serializable{
private String date_entree; private String date_entree;
private String date_sortie; private String date_sortie;
/*****Constructeur*****/
public Echantillon(int pId, String pNom, String pEspece, int pAge, String pEntree, String pSortie) { public Echantillon(int pId, String pNom, String pEspece, int pAge, String pEntree, String pSortie) {
this.setId(pId); this.setId(pId);
this.setNom(pNom); this.setNom(pNom);
this.setEspece(pEspece); this.setEspece(pEspece);
this.setAge(pAge); this.setAge(pAge);
this.setDate_entree(pEntree); this.setDate_entree(pEntree);
this.setDate_sortie(pSortie); this.setDate_sortie(pSortie);
} }
/*****Getters - Setters*****/
public int getId() { public int getId() {
return id; return id;
...@@ -71,27 +75,26 @@ public class Echantillon implements Serializable{ ...@@ -71,27 +75,26 @@ public class Echantillon implements Serializable{
this.date_sortie = date_sortie; this.date_sortie = date_sortie;
} }
public String getValueColumn(String ColumnName) { public String getValueColumn(String ColumnName) {
switch (ColumnName) { switch (ColumnName) {
case "Nom": { case "Nom": {
return getNom(); return getNom();
} }
case "Espèce": { case "Espèce": {
return getEspece(); return getEspece();
} }
case "Âge": { case "Âge": {
return Integer.toString(getAge()); return Integer.toString(getAge());
} }
case "Date entrée": { case "Date entrée": {
return (getDate_entree().toString()).substring(0,10) + " " + (getDate_entree().toString()).substring(24,29); return (getDate_entree().toString()).substring(0, 10) + " "
} + (getDate_entree().toString()).substring(24, 29);
case "Date sortie": { }
return (getDate_sortie().toString()).substring(0,10) + " " + (getDate_sortie().toString()).substring(24,29); case "Date sortie": {
} return (getDate_sortie().toString()).substring(0, 10) + " "
+ (getDate_sortie().toString()).substring(24, 29);
}
} }
return ColumnName; return ColumnName;
} }
} }
...@@ -14,10 +14,14 @@ import lry.dip.tcp.Echantillon; ...@@ -14,10 +14,14 @@ import lry.dip.tcp.Echantillon;
public class TacheSW extends SwingWorker<Integer, Echantillon> implements PropertyChangeListener { public class TacheSW extends SwingWorker<Integer, Echantillon> implements PropertyChangeListener {
/***** Attributs *****/
private ClientSocketTCP socketServeur; private ClientSocketTCP socketServeur;
private GUI gui; private GUI gui;
private ModeleTable table; private ModeleTable table;
/***** Constructeur *****/
public TacheSW(ClientSocketTCP pSocket, GUI pGui, ModeleTable pTable) { public TacheSW(ClientSocketTCP pSocket, GUI pGui, ModeleTable pTable) {
this.socketServeur = pSocket; this.socketServeur = pSocket;
addPropertyChangeListener(this); addPropertyChangeListener(this);
...@@ -25,6 +29,7 @@ public class TacheSW extends SwingWorker<Integer, Echantillon> implements Proper ...@@ -25,6 +29,7 @@ public class TacheSW extends SwingWorker<Integer, Echantillon> implements Proper
this.table = pTable; this.table = pTable;
} }
/***** Mthodes *****/
@Override @Override
protected Integer doInBackground() throws Exception { protected Integer doInBackground() throws Exception {
while (isCancelled() == false) { while (isCancelled() == false) {
......
...@@ -10,6 +10,8 @@ import lry.dip.tcp.*; ...@@ -10,6 +10,8 @@ import lry.dip.tcp.*;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class GUI extends JFrame implements Action { public class GUI extends JFrame implements Action {
/***** Attributs *****/
private JMenuBar menuBar; private JMenuBar menuBar;
private JMenu menuFichier; private JMenu menuFichier;
private JMenuItem itemAjouter, itemSupprimer, itemQuitter; private JMenuItem itemAjouter, itemSupprimer, itemQuitter;
...@@ -19,6 +21,8 @@ public class GUI extends JFrame implements Action { ...@@ -19,6 +21,8 @@ public class GUI extends JFrame implements Action {
private ClientSocketTCP client; private ClientSocketTCP client;
private TacheSW tsw; private TacheSW tsw;
/***** Constructeur *****/
public GUI(int pLarg, int pHaut, boolean pResize, String pTitre) { public GUI(int pLarg, int pHaut, boolean pResize, String pTitre) {
this.client = new ClientSocketTCP(); this.client = new ClientSocketTCP();
...@@ -65,6 +69,8 @@ public class GUI extends JFrame implements Action { ...@@ -65,6 +69,8 @@ public class GUI extends JFrame implements Action {
this.tsw.execute(); this.tsw.execute();
} }
/***** Mthodes *****/
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
...@@ -90,7 +96,7 @@ public class GUI extends JFrame implements Action { ...@@ -90,7 +96,7 @@ public class GUI extends JFrame implements Action {
UIManager.put("OptionPane.minimumSize", new Dimension(100, 100)); UIManager.put("OptionPane.minimumSize", new Dimension(100, 100));
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous vraiment quitter l'application ?", int result = JOptionPane.showConfirmDialog(null, "Voulez-vous vraiment quitter l'application ?",
"Fermeture de l'application...", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE); "Fermeture de l'application...", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE);
if (result == 0) { if (result == 0) {
System.exit(0); System.exit(0);
} }
......
...@@ -6,41 +6,49 @@ import java.util.*; ...@@ -6,41 +6,49 @@ import java.util.*;
import javax.swing.table.*; import javax.swing.table.*;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ModeleTable extends AbstractTableModel{ public class ModeleTable extends AbstractTableModel {
/***** Attributs *****/
private final String[] entetes = { "Nom", "Espce", "ge", "Date entre", "Date sortie" }; private final String[] entetes = { "Nom", "Espce", "ge", "Date entre", "Date sortie" };
private ArrayList<Echantillon> echantillons; private ArrayList<Echantillon> echantillons;
/***** Constructeur *****/
public ModeleTable() { public ModeleTable() {
this.setEchantillons(new ArrayList<Echantillon>()); this.setEchantillons(new ArrayList<Echantillon>());
} }
public ArrayList<Echantillon> getEchantillons() {
return echantillons;
}
public void setEchantillons(ArrayList<Echantillon> echantillons) { /***** Mthodes *****/
this.echantillons = echantillons;
}
public void addEchantillons(Echantillon e) { public void addEchantillons(Echantillon e) {
this.echantillons.add(e); this.echantillons.add(e);
this.fireTableDataChanged(); this.fireTableDataChanged();
} }
public void addData(Echantillon echantillon) { public void addData(Echantillon echantillon) {
this.addEchantillons(echantillon); this.addEchantillons(echantillon);
} }
public void removeData(int rowIndex) { public void removeData(int rowIndex) {
this.echantillons.remove(rowIndex); this.echantillons.remove(rowIndex);
this.fireTableDataChanged(); this.fireTableDataChanged();
} }
public void insertData(String pNom, String pEspece, int pAge, Date pEntree, Date pSortie) { public void insertData(String pNom, String pEspece, int pAge, Date pEntree, Date pSortie) {
} }
/***** Getters - Setters *****/
public ArrayList<Echantillon> getEchantillons() {
return echantillons;
}
public void setEchantillons(ArrayList<Echantillon> echantillons) {
this.echantillons = echantillons;
}
@Override @Override
public int getColumnCount() { public int getColumnCount() {
...@@ -51,7 +59,6 @@ public class ModeleTable extends AbstractTableModel{ ...@@ -51,7 +59,6 @@ public class ModeleTable extends AbstractTableModel{
public String getColumnName(int columnIndex) { public String getColumnName(int columnIndex) {
return entetes[columnIndex]; return entetes[columnIndex];
} }
@Override @Override
public int getRowCount() { public int getRowCount() {
...@@ -62,5 +69,5 @@ public class ModeleTable extends AbstractTableModel{ ...@@ -62,5 +69,5 @@ public class ModeleTable extends AbstractTableModel{
public Object getValueAt(int rowIndex, int columnIndex) { public Object getValueAt(int rowIndex, int columnIndex) {
return this.getEchantillons().get(rowIndex).getValueColumn(getColumnName(columnIndex)); return this.getEchantillons().get(rowIndex).getValueColumn(getColumnName(columnIndex));
} }
} }
...@@ -12,48 +12,52 @@ import org.junit.jupiter.api.Test; ...@@ -12,48 +12,52 @@ import org.junit.jupiter.api.Test;
import lry.dip.tcp.Echantillon; import lry.dip.tcp.Echantillon;
class ModeleTableTest { class ModeleTableTest {
/***** Attributs *****/
private static ModeleTable table; private static ModeleTable table;
static ArrayList<Echantillon> EchantillonsListe; static ArrayList<Echantillon> EchantillonsListe;
/***** Tests *****/
@BeforeAll @BeforeAll
static void initAll() { static void initAll() {
EchantillonsListe = new ArrayList<Echantillon>(); EchantillonsListe = new ArrayList<Echantillon>();
table = new ModeleTable(); table = new ModeleTable();
} }
@BeforeEach @BeforeEach
void clearDatas() { void clearDatas() {
EchantillonsListe.clear(); EchantillonsListe.clear();
Echantillon e1 = new Echantillon(1,"Echantillon1","Espece1",10,"Sat Jun 20","Sat Jun 20"); Echantillon e1 = new Echantillon(1, "Echantillon1", "Espece1", 10, "Sat Jun 20", "Sat Jun 20");
Echantillon e2 = new Echantillon(2,"Echantillon2","Espece2",10,"Sat Jun 20","Sat Jun 20"); Echantillon e2 = new Echantillon(2, "Echantillon2", "Espece2", 10, "Sat Jun 20", "Sat Jun 20");
Echantillon e3 = new Echantillon(3,"Echantillon3","Espece3",10,"Sat Jun 20","Sat Jun 20"); Echantillon e3 = new Echantillon(3, "Echantillon3", "Espece3", 10, "Sat Jun 20", "Sat Jun 20");
EchantillonsListe.add(e1); EchantillonsListe.add(e1);
EchantillonsListe.add(e2); EchantillonsListe.add(e2);
EchantillonsListe.add(e3); EchantillonsListe.add(e3);
table.setEchantillons(EchantillonsListe); table.setEchantillons(EchantillonsListe);
} }
@Test @Test
void addingData() { void addingData() {
System.out.println("Adding Datas : TEST"); System.out.println("Adding Datas : TEST");
Echantillon echantillontoAdd = new Echantillon(4,"Echantillon4","Especee4",10,"Sat Jun 20","Sat Jun 20"); Echantillon echantillontoAdd = new Echantillon(4, "Echantillon4", "Especee4", 10, "Sat Jun 20", "Sat Jun 20");
table.addData(echantillontoAdd); table.addData(echantillontoAdd);
Assertions.assertEquals(table.getEchantillons().size(),4); Assertions.assertEquals(table.getEchantillons().size(), 4);
Assertions.assertEquals(table.getEchantillons().get(3).getNom(),"Echantillon4"); Assertions.assertEquals(table.getEchantillons().get(3).getNom(), "Echantillon4");
System.out.println("Adding Datas : TEST SUCCESSFUL"); System.out.println("Adding Datas : TEST SUCCESSFUL");
} }
@Test @Test
void removingData() { void removingData() {
System.out.println("Removing Datas : TEST"); System.out.println("Removing Datas : TEST");
table.removeData(2); table.removeData(2);
Assertions.assertEquals(table.getEchantillons().size(),2); Assertions.assertEquals(table.getEchantillons().size(), 2);
Assertions.assertEquals(table.getEchantillons().get(0).getNom(),"Echantillon1"); Assertions.assertEquals(table.getEchantillons().get(0).getNom(), "Echantillon1");
Assertions.assertEquals(table.getEchantillons().get(1).getNom(),"Echantillon2"); Assertions.assertEquals(table.getEchantillons().get(1).getNom(), "Echantillon2");
System.out.println("Removing Datas : TEST SUCCESSFUL"); System.out.println("Removing Datas : TEST SUCCESSFUL");
} }
......
package lry.dip.veto; package lry.dip.veto;
import java.awt.*; import java.awt.*;
import java.text.*; import java.text.*;
import java.util.*; import java.util.*;
...@@ -9,46 +8,49 @@ import javax.swing.*; ...@@ -9,46 +8,49 @@ import javax.swing.*;
public class Panneau extends JPanel { public class Panneau extends JPanel {
/***** Attributs *****/
private JComboBox<String> titre; private JComboBox<String> titre;
private JTextField nom,espece,age; private JTextField nom, espece, age;
private JPanel panLabel, panSaisie; private JPanel panLabel, panSaisie;
private JLabel labNom,labEspece, labAge, labEntree, labSortie; private JLabel labNom, labEspece, labAge, labEntree, labSortie;
private JFormattedTextField entree,sortie; private JFormattedTextField entree, sortie;
public Panneau() { /***** Constructeur *****/
public Panneau() {
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
this.panLabel = new JPanel(); this.panLabel = new JPanel();
this.panLabel.setLayout(new GridLayout(5,1,10,10)); this.panLabel.setLayout(new GridLayout(5, 1, 10, 10));
this.panSaisie = new JPanel(); this.panSaisie = new JPanel();
this.panSaisie.setLayout(new GridLayout(5,1,10,10)); this.panSaisie.setLayout(new GridLayout(5, 1, 10, 10));
this.labNom = new JLabel("Nom:"); this.labNom = new JLabel("Nom:");
this.nom = new JTextField(); this.nom = new JTextField();
this.labEspece = new JLabel("Espece:"); this.labEspece = new JLabel("Espece:");
this.espece = new JTextField(); this.espece = new JTextField();
this.labAge = new JLabel("Age:"); this.labAge = new JLabel("Age:");
this.age = new JTextField(); this.age = new JTextField();
this.labEntree = new JLabel("Entree:"); this.labEntree = new JLabel("Entree:");
DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
this.entree = new JFormattedTextField(df); this.entree = new JFormattedTextField(df);
this.labSortie = new JLabel("Sortie:"); this.labSortie = new JLabel("Sortie:");
this.sortie = new JFormattedTextField(df); this.sortie = new JFormattedTextField(df);
this.entree.setValue(new Date()); this.entree.setValue(new Date());
this.sortie.setValue(new Date()); this.sortie.setValue(new Date());
this.panLabel.add(labNom); this.panLabel.add(labNom);
this.panSaisie.add(nom); this.panSaisie.add(nom);
this.panLabel.add(labEspece); this.panLabel.add(labEspece);
...@@ -59,34 +61,42 @@ public class Panneau extends JPanel { ...@@ -59,34 +61,42 @@ public class Panneau extends JPanel {
this.panSaisie.add(entree); this.panSaisie.add(entree);
this.panLabel.add(labSortie); this.panLabel.add(labSortie);
this.panSaisie.add(sortie); this.panSaisie.add(sortie);
add(this.panLabel, BorderLayout.WEST); add(this.panLabel, BorderLayout.WEST);
add(this.panSaisie, BorderLayout.CENTER); add(this.panSaisie, BorderLayout.CENTER);
}
/***** Mthodes *****/
public void resetForm() {
this.nom.setText("");
this.espece.setText("");
this.age.setText("");
this.entree.setValue(new Date());
this.sortie.setValue(new Date());
} }
/***** Getters - Setters *****/
public String getNom() { public String getNom() {
return this.nom.getText(); return this.nom.getText();
} }
public String getEspece() { public String getEspece() {
return this.espece.getText(); return this.espece.getText();
} }
public int getAge() { public int getAge() {
return Integer.parseInt(this.age.getText()); return Integer.parseInt(this.age.getText());
} }
public Date getEntree() { public Date getEntree() {
return (Date) this.entree.getValue(); return (Date) this.entree.getValue();
} }
public Date getSortie() { public Date getSortie() {
return (Date) this.sortie.getValue(); return (Date) this.sortie.getValue();
} }
public void resetForm() {
this.nom.setText("");
this.espece.setText("");
this.age.setText("");
this.entree.setValue(new Date());
this.sortie.setValue(new Date());
}
} }
...@@ -6,9 +6,6 @@ public class mainVeto { ...@@ -6,9 +6,6 @@ public class mainVeto {
private GUI fenetre; private GUI fenetre;
public static void main(String[] args) { public static void main(String[] args) {
GUI Fenetre = new GUI(700,400,true,"ZOO OSIRIS - Clinique Vtrinaire"); GUI Fenetre = new GUI(700, 400, true, "ZOO OSIRIS - Clinique Vtrinaire");
} }
} }
...@@ -3,7 +3,9 @@ package lry.dip.tcp; ...@@ -3,7 +3,9 @@ package lry.dip.tcp;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
public class Echantillon implements Serializable{ public class Echantillon implements Serializable {
/***** Attributs *****/
private int id; private int id;
private String nom; private String nom;
...@@ -11,7 +13,9 @@ public class Echantillon implements Serializable{ ...@@ -11,7 +13,9 @@ public class Echantillon implements Serializable{
private int age; private int age;
private String date_entree; private String date_entree;
private String date_sortie; private String date_sortie;
/***** Constructeur *****/
public Echantillon(int pId, String pNom, String pEspece, int pAge, String pEntree, String pSortie) { public Echantillon(int pId, String pNom, String pEspece, int pAge, String pEntree, String pSortie) {
this.setId(pId); this.setId(pId);
this.setNom(pNom); this.setNom(pNom);
...@@ -20,6 +24,8 @@ public class Echantillon implements Serializable{ ...@@ -20,6 +24,8 @@ public class Echantillon implements Serializable{
this.setDate_entree(pEntree); this.setDate_entree(pEntree);
this.setDate_sortie(pSortie); this.setDate_sortie(pSortie);
} }
/*****Getters - Setters*****/
public int getId() { public int getId() {
return id; return id;
...@@ -69,27 +75,25 @@ public class Echantillon implements Serializable{ ...@@ -69,27 +75,25 @@ public class Echantillon implements Serializable{
this.date_sortie = date_sortie; this.date_sortie = date_sortie;
} }
public String getValueColumn(String ColumnName) { public String getValueColumn(String ColumnName) {
switch (ColumnName) { switch (ColumnName) {
case "Nom": { case "Nom": {
return getNom(); return getNom();
} }
case "Espèce": { case "Espèce": {
return getEspece(); return getEspece();
} }
case "Âge": { case "Âge": {
return Integer.toString(getAge()); return Integer.toString(getAge());
} }
case "Date entrée": { case "Date entrée": {
return (getDate_entree().toString()).substring(0,10) + " " + (getDate_entree().toString()).substring(24,29); return (getDate_entree().toString()).substring(0, 10) + " "
} + (getDate_entree().toString()).substring(24, 29);
case "Date sortie": { }
return getDate_sortie().toString(); case "Date sortie": {
} return getDate_sortie().toString();
}
} }
return ColumnName; return ColumnName;
} }
} }
...@@ -13,114 +13,116 @@ import java.net.Socket; ...@@ -13,114 +13,116 @@ import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
public class ServerSocketTCP extends Thread{ public class ServerSocketTCP extends Thread {
/***** Attributs *****/
private ServerSocket server; private ServerSocket server;
private Inet4Address IPServeur; private Inet4Address IPServeur;
private int portServeur; private int portServeur;
private boolean tacheServeur; private boolean tacheServeur;
private int nbClients; private int nbClients;
private ArrayList<gestionClient> listeClients; private ArrayList<gestionClient> listeClients;
private commandesServeur cmd; private commandesServeur cmd;
private gestionBDD bdd; private gestionBDD bdd;
/***** Constructeur *****/
public ServerSocketTCP(int pPort, String pIP, gestionBDD pBdd) { public ServerSocketTCP(int pPort, String pIP, gestionBDD pBdd) {
this.bdd = pBdd; this.bdd = pBdd;
this.portServeur = pPort; this.portServeur = pPort;
try { try {
this.IPServeur = (Inet4Address)InetAddress.getByName(pIP); this.IPServeur = (Inet4Address) InetAddress.getByName(pIP);
} catch (UnknownHostException event) { } catch (UnknownHostException event) {
System.out.println("Le serveur n'est pas sur coute. Vrifier que le format de l'adresse IP est correct."); System.out.println("Le serveur n'est pas sur coute. Vrifier que le format de l'adresse IP est correct.");
} }
this.nbClients = 0; this.nbClients = 0;
this.listeClients = new ArrayList<>(); this.listeClients = new ArrayList<>();
try { try {
this.server = new ServerSocket(this.portServeur, 0, this.IPServeur); this.server = new ServerSocket(this.portServeur, 0, this.IPServeur);
} catch (IOException IOex) { } catch (IOException IOex) {
System.out.println("Le serveur n'est pas sur coute. Vrifier que le port soit disponible."); System.out.println("Le serveur n'est pas sur coute. Vrifier que le port soit disponible.");
} }
this.cmd = new commandesServeur(this); this.cmd = new commandesServeur(this);
this.cmd.start(); this.cmd.start();
} }
/***** Mthodes *****/
public void run() { public void run() {
this.tacheServeur = true; this.tacheServeur = true;
while (this.tacheServeur) { while (this.tacheServeur) {
try { try {
new gestionClient(this.server.accept(), this, this.bdd); new gestionClient(this.server.accept(), this, this.bdd);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
public synchronized void envoyerATous(Echantillon echantillon) { public synchronized void envoyerATous(Echantillon echantillon) {
for (int i = 0; i < this.listeClients.size(); i++) for (int i = 0; i < this.listeClients.size(); i++)
((gestionClient)this.listeClients.get(i)).envoyerReponse(echantillon); ((gestionClient) this.listeClients.get(i)).envoyerReponse(echantillon);
} }
public synchronized int ajouterClient(gestionClient pClient) { public synchronized int ajouterClient(gestionClient pClient) {
this.nbClients++; this.nbClients++;
this.listeClients.add(pClient); this.listeClients.add(pClient);
pClient.start(); pClient.start();
return this.listeClients.size() - 1; return this.listeClients.size() - 1;
} }
public synchronized void deconnecterTousClients() { public synchronized void deconnecterTousClients() {
for (int i = 0; i < this.listeClients.size(); i++) for (int i = 0; i < this.listeClients.size(); i++)
((gestionClient)this.listeClients.get(i)).deconnecterClient(); ((gestionClient) this.listeClients.get(i)).deconnecterClient();
} }
public synchronized void supprimerClient(int numClient) { public synchronized void supprimerClient(int numClient) {
this.listeClients.remove(numClient); this.listeClients.remove(numClient);
this.nbClients--; this.nbClients--;
for (int j = numClient; j < this.listeClients.size(); j++) for (int j = numClient; j < this.listeClients.size(); j++)
((gestionClient)this.listeClients.get(numClient)).setNumClient(((gestionClient)this.listeClients.get(numClient)).getNumClient() - 1); ((gestionClient) this.listeClients.get(numClient))
} .setNumClient(((gestionClient) this.listeClients.get(numClient)).getNumClient() - 1);
}
public void lancerServeur(int pPort, String pIP){
public void lancerServeur(int pPort, String pIP) {
try { try {
this.portServeur = pPort; this.portServeur = pPort;
this.IPServeur = (Inet4Address) InetAddress.getByName(pIP); this.IPServeur = (Inet4Address) InetAddress.getByName(pIP);
this.server = new ServerSocket(this.portServeur,1,this.IPServeur); this.server = new ServerSocket(this.portServeur, 1, this.IPServeur);
System.out.println(this.portServeur+this.IPServeur.toString()); System.out.println(this.portServeur + this.IPServeur.toString());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void arreterServeur(){ public void arreterServeur() {
try { try {
this.server.close(); this.server.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
/***** Getters - Setters *****/
public int getNbClients() { public int getNbClients() {
return this.nbClients; return this.nbClients;
} }
public Inet4Address getIPServeur() { public Inet4Address getIPServeur() {
return this.IPServeur; return this.IPServeur;
} }
public int getPortServeur() { public int getPortServeur() {
return this.portServeur; return this.portServeur;
} }
public ServerSocket getServerSocket() { public ServerSocket getServerSocket() {
return this.server; return this.server;
} }
public void setTache(boolean pTache) { public void setTache(boolean pTache) {
this.tacheServeur = pTache; this.tacheServeur = pTache;
} }
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter