diff --git a/Application/Clavardage/.classpath b/Application/Clavardage/.classpath
deleted file mode 100644
index fb663ea..0000000
--- a/Application/Clavardage/.classpath
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Application/Clavardage/.project b/Application/Clavardage/.project
deleted file mode 100644
index 7ee0ed5..0000000
--- a/Application/Clavardage/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- Clavardage
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
diff --git a/Application/Clavardage/.settings/org.eclipse.jdt.core.prefs b/Application/Clavardage/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 3a21537..0000000
--- a/Application/Clavardage/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,11 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.8
diff --git a/Application/Clavardage/bin/.gitignore b/Application/Clavardage/bin/.gitignore
deleted file mode 100644
index 5e4c200..0000000
--- a/Application/Clavardage/bin/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/websocket/
-/controller/
diff --git a/Application/Clavardage/bin/model/Chat.class b/Application/Clavardage/bin/model/Chat.class
deleted file mode 100644
index da4a6ed..0000000
Binary files a/Application/Clavardage/bin/model/Chat.class and /dev/null differ
diff --git a/Application/Clavardage/bin/model/LocalUser.class b/Application/Clavardage/bin/model/LocalUser.class
deleted file mode 100644
index d1eddd8..0000000
Binary files a/Application/Clavardage/bin/model/LocalUser.class and /dev/null differ
diff --git a/Application/Clavardage/bin/model/Message.class b/Application/Clavardage/bin/model/Message.class
deleted file mode 100644
index 647193f..0000000
Binary files a/Application/Clavardage/bin/model/Message.class and /dev/null differ
diff --git a/Application/Clavardage/bin/model/Msg_Text.class b/Application/Clavardage/bin/model/Msg_Text.class
deleted file mode 100644
index 39d9e99..0000000
Binary files a/Application/Clavardage/bin/model/Msg_Text.class and /dev/null differ
diff --git a/Application/Clavardage/bin/model/RemoteUser.class b/Application/Clavardage/bin/model/RemoteUser.class
deleted file mode 100644
index 27ff6fe..0000000
Binary files a/Application/Clavardage/bin/model/RemoteUser.class and /dev/null differ
diff --git a/Application/Clavardage/bin/model/User.class b/Application/Clavardage/bin/model/User.class
deleted file mode 100644
index 05b9e9e..0000000
Binary files a/Application/Clavardage/bin/model/User.class and /dev/null differ
diff --git a/Application/Clavardage/bin/view/Interface$1.class b/Application/Clavardage/bin/view/Interface$1.class
deleted file mode 100644
index 8d7c31e..0000000
Binary files a/Application/Clavardage/bin/view/Interface$1.class and /dev/null differ
diff --git a/Application/Clavardage/bin/view/Interface$2.class b/Application/Clavardage/bin/view/Interface$2.class
deleted file mode 100644
index 14fcfdf..0000000
Binary files a/Application/Clavardage/bin/view/Interface$2.class and /dev/null differ
diff --git a/Application/Clavardage/bin/view/Interface$3.class b/Application/Clavardage/bin/view/Interface$3.class
deleted file mode 100644
index d9d6279..0000000
Binary files a/Application/Clavardage/bin/view/Interface$3.class and /dev/null differ
diff --git a/Application/Clavardage/bin/view/Interface.class b/Application/Clavardage/bin/view/Interface.class
deleted file mode 100644
index b0ebed0..0000000
Binary files a/Application/Clavardage/bin/view/Interface.class and /dev/null differ
diff --git a/Application/Clavardage/src/controller/Controller.java b/Application/Clavardage/src/controller/Controller.java
deleted file mode 100644
index 77e672c..0000000
--- a/Application/Clavardage/src/controller/Controller.java
+++ /dev/null
@@ -1,547 +0,0 @@
-package controller;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.net.URISyntaxException;
-import java.net.UnknownHostException;
-import java.sql.SQLException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-
-import javax.swing.JOptionPane;
-import javax.websocket.DeploymentException;
-
-import model.Chat;
-import model.LocalUser;
-import model.Message;
-import model.Msg_Text;
-import model.RemoteUser;
-import view.Interface;
-import websocket.Appel;
-
-public class Controller {
-
- /*** CONSTANTES ***/
- final int NB_SECOND_WAITING_RESPONSE_BROADCAST = 1;
-
- // TO REMOVE when we use broadcast
- final static int portUDPlistening_remoteUsr1 = 31001;
- final static int portUDPlistening_remoteUsr2 = 31002;
- final static int portUDPlistening_remoteUsr3 = 31003;
- final static int portUDPlistening_local = 31004;
- final static int [] tabBroadcast = {portUDPlistening_remoteUsr1,portUDPlistening_remoteUsr2,portUDPlistening_remoteUsr3,portUDPlistening_local};
-
- public Boolean interfaceRunning = false;
- /*** ATTRIBUTS ***/
- protected LocalUser myUser;
- protected Interface view;
- private TListeningUDP udp_connect_thread;
- private TListeningTCPConnection tcp_connect_thread;
- private Historique histoire;
- protected Chat activeChat;
-
- /**
- * Constructor of Controller
- * @parametres
- * @param portUDPsend : int => le numéro de port pour envoyer ces informations lors d'un changements ou d'une nouvelle connexion
- * @param portUDPlistening : int => le numéro de port pour recevoir les informations des nouveaux utilisateurs ou les changements
- * @param portTCP : int => le numéro de port pour commencer une nouvelle conversation
- * @throws IOException
- * @descrition
- *
- * On récupère l'adresse de la machine, on demande un pseudo à l'utilisateur que l'on vérifie
- * Une fois validé l'utilisateur devient actif :
- * - écoute UDP pour les pseudos
- * - écoute TCP pour de nouvelles conversation
- * - notification aux autres utilisateurs actifs
- *
- */
- private Controller(int portUDPsend,int portUDPlistening,int portTCP,Historique histoire) throws IOException {
- this.histoire= histoire;
-
- // Récupération de l'adresse IP local
- InetAddress addIP = null;
- try
- {
- addIP = InetAddress.getLocalHost();
- }
- catch(UnknownHostException e) {
- JOptionPane.showMessageDialog(null ,"Could not find local address!");
- }
-
- // Création de l'utilisateur
- this.myUser = new LocalUser("Unknown",addIP,portUDPsend,portUDPlistening,portTCP);
-
- try {
- this.myUser.setPseudo(this.initPseudo()); // Initialisation du pseudo manuel
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- // Création des threads d'écoutes
- this.udp_connect_thread = new TListeningUDP("UDP Listening thread",this);
- this.udp_connect_thread.start();
- this.tcp_connect_thread = new TListeningTCPConnection("TCP main Listening thread",this);
- this.tcp_connect_thread.start();
-
- // Notification des utilisateurs distants
- notify_remote_users();
-
- // Création de l'interface
- interfaceRunning =true;
- view=Interface.createAndShowGUI(this);
- }
-
- /**
- * Constructor of Controller
- * @parametres
- * @param portUDPsend : int => le numéro de port pour envoyé ces informations lors d'un changements ou d'une nouvelle connexion
- * @param portUDPlistening : int => le numéro de port pour recevoir les informations des nouveaux utilisateurs ou les changements
- * @param portTCP : int => le numéro de port pour commencer une nouvelle conversation
- * @descrition
- *
- * On récupère l'adresse de la machine, on demande un pseudo à l'utilisateur que l'on vérifie
- * Une fois validé l'utilisateur devient actif :
- * - écoute UDP pour les pseudos
- * - écoute TCP pour de nouvelles conversation
- * - notification aux autres utilisateurs actifs
- *
- */
- private Controller(int portUDPsend,int portUDPlistening,int portTCP,String pseudo,Historique histoire) throws IOException{
-
- this.histoire=histoire;
-
- // Récupération de l'adresse IP local
- InetAddress addIP = null;
- try
- {
- addIP = InetAddress.getLocalHost();
-
- }
- catch(UnknownHostException e) {
- JOptionPane.showMessageDialog(null ,"Could not find local address!");
- }
-
- // Création de l'utilisateur
- this.myUser = new LocalUser(pseudo,addIP,portUDPsend,portUDPlistening,portTCP);
- try {
- if(this.validatePseudo(pseudo)) {
-
-
- this.udp_connect_thread = new TListeningUDP("UDP Listening thread",this);
- this.udp_connect_thread.start();
-
- this.tcp_connect_thread = new TListeningTCPConnection("TCP main Listening thread",this);
- this.tcp_connect_thread.start();
-
-
- // Notification des utilisateurs distants
- notify_remote_users();
-
- // Création de l'interface
- interfaceRunning =true;
- view=Interface.createAndShowGUI(this);
- }
- else {
- System.out.println("Unavailable "+pseudo);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
-
- /*** GETTERS ***/
- public LocalUser getMyUser() {
- return myUser;
- }
- public Interface getview() {
- return view;
- }
- public TListeningUDP getUdp_connect_thread() {
- return udp_connect_thread;
- }
- public TListeningTCPConnection getTcp_connect_thread() {
- return tcp_connect_thread;
- }
- public Historique getHistory() {
- return histoire;
- }
-
- /*** SETTERS ***/
- public void setMyUser(LocalUser myUser) {
- this.myUser = myUser;
- }
- public void setview(Interface view) {
- this.view = view;
- }
- public void setUdp_connect_thread(TListeningUDP udp_connect_thread) {
- this.udp_connect_thread = udp_connect_thread;
- }
- public void setTcp_connect_thread(TListeningTCPConnection tcp_connect_thread) {
- this.tcp_connect_thread = tcp_connect_thread;
- }
- public void setHistory(Historique histoire) {
- this.histoire=histoire;
- }
-
- /**************************** Initialisation pseudo et découverte utilisateur distant (+notification utilisateurs distants) **********************************/
-
- /** initPseudo
- *
- * Demande à l'utilisateur de rentrer un pseudo et valide de ce dernier en demandant aux
- * utilisateurs distants leurs informations
- *
- */
- public String initPseudo() throws IOException {
- String tmpPseudo = JOptionPane.showInputDialog(null, "Enter nickname:"); // Read user input
-
- while(!(this.validatePseudo(tmpPseudo))) { // On demande aux autres utilisateurs de nous envoyer leurs informations et on test si le pseudo est déjà utilisé
- tmpPseudo = JOptionPane.showInputDialog(null, "Enter another nickname:"); // Read user input
- }
-
- //sc1.close();
- JOptionPane.showMessageDialog(null ,"Your nickname : " + tmpPseudo + " is valid !");
-
- return tmpPseudo;
- }
-
- /** changePseudo
- *
- * Demande à l'utilisateur de rentrer un pseudo et valide de ce dernier en demandant aux
- * utilisateurs distants leurs informations.
- * On regarde si le pseudo est bien différent de l'ancien
- *
- */
- public void changePseudo() throws IOException {
- String oldPseudo = this.myUser.getPseudo(); //Saves the old one for comparison
-
- String tmpPseudo = view.ChangePseudotextField.getText(); // Read user input
-
- if(!(this.validatePseudo(tmpPseudo)) || tmpPseudo.equals(oldPseudo)) {
- view.Pseudolabel.setText("Already exists, enter another nickname. Your current username is: " + oldPseudo); // Read user input
- tmpPseudo = view.ChangePseudotextField.getText(); // Read user input
- }
- else {
- this.myUser.setPseudo(tmpPseudo);
- JOptionPane.showMessageDialog(null ,"Your new nickname : " + tmpPseudo + " is valid !");
- this.notify_remote_users();
- }
- }
-
-
- /** validatePseudo
- *
- * *tmpPseudo : String => Le pseudo à valider
- *
- * Envoi en broadcast (pour l'instant envoi sur les ports de notre ordinateur) d'une demande d'information
- *
- * On attend les réponses pendant 5 secondes
- *
- * On valide le pseudo en fonction des pseudos reçu
- *
- * On en profite pour ajouter les utilisateurs répondant à notre liste d'utilisateur distant (RemoteUser)
- *
- */
- public Boolean validatePseudo(String tmpPseudo) throws IOException {
- Boolean valid = true;
-
- DatagramSocket dgramSocket = new DatagramSocket(this.myUser.getPortUDPsend(),this.myUser.getAddIP());
-
- // Création du message à envoyer
- String toSend = this.myUser.getAddIP().getHostAddress()+":"+this.myUser.getPortUDPsend()+":info";
-
- // Broadcast du message
- broadcast(dgramSocket,toSend);
-
- /*** For 5 seconds wait for answer : validate pseudo & add to userlist ***/
- byte[] buffer = new byte[256];
- DatagramPacket inPacket;
- String response = null;
- String[] tabresponse= new String [4];
- dgramSocket.setSoTimeout(1000);
- Boolean arecu;
- int nbReponse =0;
- System.out.println("("+myUser.getPseudo()+") Waiting for pseudo validation ...");
- Date oldDate = new Date();
- Date newDate = new Date();
-
- while( (newDate.getTime()-oldDate.getTime()) < NB_SECOND_WAITING_RESPONSE_BROADCAST*1000 && valid) {
- nbReponse++;
- inPacket= new DatagramPacket(buffer, buffer.length);
- arecu=true;
- try{
- dgramSocket.receive(inPacket);
- }catch (Exception e) {
- arecu=false;
- }
-
- buffer = inPacket.getData();
- response = new String(buffer);
- if(arecu) {
- // On découpe la réponse en tableau de string ([adresseIP,tcpPort,nickname])
- tabresponse = response.split(":");
- // Si reception on ajoute l'utilisateur à notre liste d'utilisateur distant
- this.myUser.addRemoteUser(InetAddress.getByName(tabresponse[0]),Integer.parseInt(tabresponse[1]),tabresponse[2]);
- valid= (tmpPseudo.compareTo(tabresponse[2])!=0); // On regarde la différence entre notre pseudo et le pseudo reçu
- }
- newDate = new Date();
- }
-
-
- dgramSocket.close();
- if(!valid) {
- JOptionPane.showMessageDialog(null ,"Nickname : "+tmpPseudo +" is taken !");
- }
- return valid;
- }
-
- /***broadcast
- *
- * @param dgramSocket
- * @param toSend
- * @param broadcastIP
- * @throws IOException
- *
- * Simulation of broadcast with port given (tabBroadcast)
- *
- */
- public void broadcast(DatagramSocket dgramSocket,String toSend) throws IOException {
- InetAddress broadcastIP = InetAddress.getLocalHost();
- DatagramPacket outPacket = null;
- int tabBroadcastSize = tabBroadcast.length;
- for(int i=0;i
- * En utilisant le port UDP d'envoi, on envoie en broadcast les informations nous concernant
- *
- * @throws IOException
- */
- public void notify_remote_users() throws IOException {
- DatagramSocket dgramSocket= null;
- try {
- dgramSocket= new DatagramSocket(this.myUser.getPortUDPsend(),this.myUser.getAddIP());
- } catch (IOException e) {
- e.printStackTrace();
- }
- // Send to other active user (simulation of broadcast)
- String toSend = this.myUser.getAddIP().getHostAddress()+":"+this.myUser.getPortTCP()+":"+this.myUser.getPseudo()+":notify";
- broadcast(dgramSocket,toSend);
- dgramSocket.close();
- }
-
-
- /**************************** Gestion des sessions **********************************/
-
- public Chat openSession(RemoteUser rm) {
- Chat c = myUser.addChats(rm); // Create chat and add it to myUser
-
- /*** Create socket send => ask connection to server of rm ***/
- Socket link=null;
- try {
- // Connection => server tcp rm
- System.out.println("("+this.myUser.getPseudo()+") Connecting to "+c.getRemoteUser().getPortTCP()+" of " + c.getRemoteUser().getPseudo());
- link=new Socket(c.getRemoteUser().getAddIP(),c.getRemoteUser().getPortTCP()/*, InetAddress.getLocalHost() ,myUser.getPortTCP()*/);
- c.setSocket(link);
- // Sending data for identification (TO REMOVE IF != IP)
- sendInfoProcess(Integer.toString(myUser.getPortTCP()), c); // tell rm session STOP
- }catch(IOException e) {
- System.out.println("Error linking to TCP server of "+ c.getRemoteUser().getPortTCP());
- }
-
-
- /*** recup history and put it in model ***/
- try {
- try {
- c.addListMessage(this.getHistory().retrieveMessage(getMyUser(), c.getRemoteUser()));
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- } catch (SQLException e) {
- System.out.println("souci avec le retrieveMsgSQL");
- e.printStackTrace();
- }
- return c;
- }
-
-
-
- public String askOpenSession(int index) {
- String history="";
- RemoteUser rm = myUser.getRemoteUsersList().get(index);
- Chat c;
-
- /*** Recup or create chat ***/
- if(myUser.getChatIndexOf(rm)!=-1) { // if already a chat open
- c = myUser.getChats().get(myUser.getChatIndexOf(rm));
- JOptionPane.showMessageDialog(null ,"Active session with "+c.getRemoteUser().getPseudo()+" loading history");
- }
- else { // else create it
- c=openSession(rm);
- JOptionPane.showMessageDialog(null ,"New session with "+rm.getPseudo());
- }
-
- // Look for history
-
- int nbMessage = c.getMessages().size();
- for(int i=0;i lstCtr = new ArrayList();
-
- // REMOTE USERS
- Controller ctr1 = new Controller(31011,portUDPlistening_remoteUsr1,31021,"Theau",histoire);
- lstCtr.add(ctr1);
- Controller ctr2 = new Controller(31012,portUDPlistening_remoteUsr2,31022,"Leonie",histoire);
- lstCtr.add(ctr2);
- Controller ctr3 = new Controller(31013,portUDPlistening_remoteUsr3,31023,"Alexandre",histoire);
- lstCtr.add(ctr3);
-
- // LOCAL USER
- Controller ctr = new Controller(31014,portUDPlistening_local,31024,histoire);
- lstCtr.add(ctr);
-
- Appel app=new Appel();
- app.test();
-
- /** Loop **/
- Boolean running = isRunning(lstCtr);
- while(running) {
- running = isRunning(lstCtr);
- }
-
- System.out.println("Fin de la boucle");//TOREMOVE
-
- /** End - Close thread and socket for every controller**/
- closeThreads(lstCtr);
- System.out.println("end program");
- JOptionPane.showMessageDialog(null ,"END");
- }
-
- static boolean isRunning(ArrayList lstCtr){
- boolean isRunning=false;
- for(Controller ctr : lstCtr) {
- isRunning|=ctr.interfaceRunning;
- }
- return isRunning;
- }
-
- static void closeThreads(ArrayList lstCtr) {
- for(Controller ctr : lstCtr) {
- ctr.close();
- }
- }
-
-}
-
-
diff --git a/Application/Clavardage/src/controller/Historique.java b/Application/Clavardage/src/controller/Historique.java
deleted file mode 100644
index 651416e..0000000
--- a/Application/Clavardage/src/controller/Historique.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package controller;
-
-import java.sql.Connection;
-
-import java.sql.Date;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Calendar;
-
-import javax.sql.rowset.JdbcRowSet;
-
-import model.Message;
-import model.Msg_Text;
-
-public class Historique {
-
- public void saveMessage(model.User author, model.RemoteUser receiver, String input, String date) {
- try {
- Class.forName("java.sql.Driver");
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- Connection con = null;
- try {
- con = DriverManager.getConnection("jdbc:mysql://srv-bdens.insa-toulouse.fr:3306","tp_servlet_003","povu3Ma2");
- } catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- Statement stat = null;
- try {
- stat = con.createStatement();
- } catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- int nb_changed_rows = 0;
- try {
- nb_changed_rows = stat.executeUpdate("USE tp_servlet_003");
- } catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
-/*
- try {
- nb_changed_rows = stat.executeUpdate("CREATE TABLE chat ( user_IPcode1 INTEGER, user_IPcode2 INTEGER ,Message VARCHAR(450) ,temps VARCHAR(450) )");
- }catch (Exception e) {
- e.printStackTrace();
-
- }
- System.out.println("coucou");
-*/
- try {
- nb_changed_rows = stat.executeUpdate("INSERT INTO chat VALUES ('"+author.getIPcode()+"','"+receiver.getIPcode()+"','"+input+"','"+date+"')");
- } catch (SQLException e) {
- System.out.println("insertion pas établie");
- e.printStackTrace();
- }
-// try {
-// nb_changed_rows = stat.executeUpdate("DELETE FROM chat WHERE data(VARCHAR(255))="valeur"");
-// } catch (SQLException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
- try {
- stat.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- con.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- public ArrayList retrieveMessage(model.LocalUser usr, model.RemoteUser rmusr) throws SQLException, ClassNotFoundException {
- ArrayList messages=new ArrayList();
-
- Class.forName("java.sql.Driver");
- Connection con=DriverManager.getConnection("jdbc:mysql://srv-bdens.insa-toulouse.fr:3306","tp_servlet_003","povu3Ma2");
- Statement stat = null;
- stat = con.createStatement();
- stat.executeUpdate("USE tp_servlet_003");
-/*
- Statement stat2 = null;
- stat2 = con.createStatement();
- stat.executeUpdate("USE tp_servlet_003");
-*/
-
- //int nb_changed_rows;
-
- String query = "SELECT user_IPcode1 ,Message, temps"
- +" FROM chat WHERE (user_IPcode1="+usr.getIPcode()
- +" AND user_IPcode2="+rmusr.getIPcode()+") "
- +"OR (user_IPcode1="+rmusr.getIPcode()+" "
- + "AND user_IPcode2="+usr.getIPcode()+") "
- + "ORDER BY temps;";
- ResultSet resultQueryRS=(stat.executeQuery(query));
-
- int autorIPcode;
- String message;
- String strDate;
-
- boolean encore = resultQueryRS.next();
- while(encore) {
- autorIPcode=resultQueryRS.getInt(1);
- message=resultQueryRS.getString(2);;
- strDate=resultQueryRS.getString(3);
- if(usr.getIPcode()==autorIPcode) {
- messages.add(new Msg_Text(usr,strDate,message));
- }
- else {
- messages.add(new Msg_Text(rmusr,strDate,message));
- }
- encore=resultQueryRS.next();
-
- }
- return messages;
- }
-
-
-
-
-}
diff --git a/Application/Clavardage/src/controller/ListeningThread.java b/Application/Clavardage/src/controller/ListeningThread.java
deleted file mode 100644
index 83f0a80..0000000
--- a/Application/Clavardage/src/controller/ListeningThread.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package controller;
-
-
-public abstract class ListeningThread extends Thread{
-
- protected Controller controller;
-
- public ListeningThread(String s,Controller controller) {
- super(s);
- this.controller = controller;
- }
-
- public abstract void run();
-
- public abstract void close();
-}
diff --git a/Application/Clavardage/src/controller/ListeningThreadTCPChat.java b/Application/Clavardage/src/controller/ListeningThreadTCPChat.java
deleted file mode 100644
index 8d6ea26..0000000
--- a/Application/Clavardage/src/controller/ListeningThreadTCPChat.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package controller;
-
-import model.Chat;
-import model.Msg_Text;
-import model.RemoteUser;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.Socket;
-import java.util.Calendar;
-import java.util.Date;
-
-public class ListeningThreadTCPChat extends ListeningThread{
-
- private Socket socket;
-
- /* CONSTRUCTOR OF ListeningThreadTCPConnection
- * @parametres
- * @param s : String => nom du thread
- * @param myUser : User => utilisateur utilisant ce thread
- * @description
- *
- *
- */
- public ListeningThreadTCPChat(String s,Controller controller,Socket socket) {
- super(s,controller);
- this.socket=socket;
- // TODO OpenSession si ouverture exterieur
- }
-
- /* run
- * @description
- *
- *
- *
- */
- public void run() {
- /**** function variables ****/
- BufferedReader in = null;
- String msg = null;
- String input;
- String dateString;
- Date date;
- Calendar date1=Calendar.getInstance();
-
-
- Chat c = null;
-
-
- try {
- in =new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- /************ Check rm user information **********/
- // check data identification from rm user | TO REMOVE IF !=IP
- int rmPortTCP = -1;
- try {
- rmPortTCP = Integer.parseInt(in.readLine());
- } catch (NumberFormatException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- RemoteUser rm = new RemoteUser("Unknown",this.socket.getInetAddress(),rmPortTCP);
-
- int indexRM = controller.myUser.getActiveUserIndexOf(rm);
- // Check if rm is identifiable
- /*System.out.println(rm);
- for(int i=0;i "+rm.getPseudo()+" : "+input);
- Msg_Text message = new Msg_Text(rm,input);
- c.addMessage(message);
- if(controller.activeChat==c) {
- controller.view.notifyNewMessage("("+message.getDate()+")\n"+c.getRemoteUser().getPseudo()+" : "+input);
- }
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- else {
- System.out.println("("+this.controller.myUser.getPseudo()+") Remote User unidentifiable => CLOSING CONNECTION");
- }
-
-
-
-
-
-
-
- }
-
- /* close
- * @description
- *
- * ferme le socket d'écoute TCP pour le chat
- * interrupt TCP listening thread pour le chat
- *
- */
- public void close() {
- try {
- this.socket.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- System.out.println("End of listing thread UDP ("+this.controller.myUser.getPseudo()+")");
- try {
- this.interrupt();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
-}
diff --git a/Application/Clavardage/src/controller/ListeningThreadTCPConnection.java b/Application/Clavardage/src/controller/ListeningThreadTCPConnection.java
deleted file mode 100644
index 31833a4..0000000
--- a/Application/Clavardage/src/controller/ListeningThreadTCPConnection.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package controller;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-public class ListeningThreadTCPConnection extends ListeningThread{
-
- private Socket socket_tcp=null;
- private int nbChat = 0;
- /* CONSTRUCTOR OF ListeningThreadTCPConnection
- * @parametres
- * @param s : String => nom du thread
- * @param myUser : User => utilisateur utilisant ce thread
- * @description
- *
- *
- */
- public ListeningThreadTCPConnection(String s,Controller controller) {
- super(s,controller);
-
- }
-
- public void accept(ServerSocket servSocket) throws IOException {
- Socket socket_tcp= servSocket.accept();
- this.nbChat++;
- ListeningThreadTCPChat threadtcpchat = new ListeningThreadTCPChat("Chat_of_"+controller.myUser.getPseudo()+"_"+nbChat,controller,socket_tcp);
- threadtcpchat.start();
- threadtcpchat.interrupt();
-
- }
-
- /* run
- * @description
- *
- * écoutes les messages TCP tant que l'utilisateur est actif
- * Traitement
- * Si réception d'une demande, créer un thread pour la conversation
- *
- */
- public void run(){
-
- // Tant que l'utilisateur est actif on attends la demande de nouvelle conversation
- ServerSocket servSocket=null;
- try {
- servSocket = new ServerSocket(controller.myUser.getPortTCP());
- System.out.println("("+this.controller.myUser.getPseudo()+") Server is listening on port "+this.controller.myUser.getPortTCP());
- } catch (IOException e) {
- System.out.println("("+this.controller.myUser.getPseudo()+") Server is not listening on port "+this.controller.myUser.getPortTCP());
- e.printStackTrace();
- }
- while(true) {
- System.out.println("("+this.controller.myUser.getPseudo()+") TCP Server waiting for new connection ...");
-
- try {
- this.accept(servSocket);
- System.out.println("("+this.controller.myUser.getPseudo()+") NEW CONNECTION");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
-
- }
-
- }
-
- /* close
- * @description
- *
- * ferme le socket d'écoute TCO
- * interrupt UDP listening threadS
- *
- */
- public void close() {
- try {
- this.socket_tcp.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- System.out.println("End of listing thread TCP ("+this.controller.myUser.getPseudo()+")");
- try {
- this.interrupt();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
-
-}
-
-
diff --git a/Application/Clavardage/src/controller/ListeningThreadUDP.java b/Application/Clavardage/src/controller/ListeningThreadUDP.java
deleted file mode 100644
index 12d51c3..0000000
--- a/Application/Clavardage/src/controller/ListeningThreadUDP.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package controller;
-
-import model.LocalUser;
-
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-public class ListeningThreadUDP extends ListeningThread{
-
- private DatagramSocket dgramSocket = null;
-
-
- /* CONSTRUCTOR OF UserListeningThreadUDP
- * @parametres
- * @param s : String => nom du thread
- * @param user : User => utilisateur utilisant ce thread
- * @description
- *
- * Appel du constructeur de la classe hérité
- * Création d'un socket d'écoute UDP
- *
- */
- public ListeningThreadUDP(String s,Controller controller) {
- super(s,controller);
- try {
- this.dgramSocket = new DatagramSocket(this.controller.myUser.getPortUDPlistening(),this.controller.myUser.getAddIP());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- /* run
- * @description
- *
- * écoutes les messages UDP tant que l'utilisateur est actif
- * Traitement
- * 1) Si demande d'information => envoi ses informations
- * 2) Si réception d'information => ajoute les informations
- *
- */
- public void run(){
-
- // Tant que l'utilisateur est actif on attends les messages des nouveaux utilisateurs et changements des utilisateurs actifs
- while(true) {
-
- // Réception du message
- byte[] buffer = new byte[256];
- DatagramPacket inPacket= new DatagramPacket(buffer, buffer.length);
- try {
- dgramSocket.receive(inPacket);
- } catch (Exception e) {
- e.printStackTrace();
- }
- buffer = inPacket.getData();
-
- // Traitement en fonction du message reçu
- String receiveMsg = new String(buffer);
- String [] tabMsg = receiveMsg.split(":");
-
-
- // si demande d'information d'un nouvel utilisateur
- if(tabMsg.length==3) {
- InetAddress itsIP = null;
- try {
- itsIP = InetAddress.getByName(tabMsg[0].split("/")[1]); // On récupère l'adresse IP de l'utilisateur distant
- } catch (UnknownHostException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- int senderUDPport = Integer.parseInt(tabMsg[1]); // On récupère le port UDP de l'utilisateur distant
-
- String toSend = controller.myUser.getAddIP().toString()+":"+controller.myUser.getPortTCP()+":"+controller.myUser.getPseudo()+":test";
- DatagramPacket outPacket= new DatagramPacket(toSend.getBytes(), toSend.length(),itsIP, senderUDPport);
-
- try {
- dgramSocket.send(outPacket);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- // Si un nouvel utilisateur passe en mode actif ou changement d'information
- else {
- try {
- // On récupère l'adresse IP et le port TCP de l'utilisateur distant et ajout à la liste de l'utilisateur utilisant ce thread
- controller.myUser.addRemoteUser(InetAddress.getByName(tabMsg[0].split("/")[1]),Integer.parseInt(tabMsg[1]),tabMsg[2]);
- } catch (NumberFormatException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- if(controller.interfaceRunning) {
- controller.view.updateActiveUsers();
- }
- }
-
-
- }
-
-
- }
-
- /* close
- * @description
- *
- * Ferme le socket d'écoute UDP
- * Interrompt le thread d'écoute UDP
- *
- */
- public void close() {
- this.dgramSocket.close();
- System.out.println("End of listing thread UDP ("+this.controller.myUser.getPseudo()+")");
- try {
- this.interrupt();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
-}
diff --git a/Application/Clavardage/src/controller/TListeningTCPChat.java b/Application/Clavardage/src/controller/TListeningTCPChat.java
deleted file mode 100644
index ab8150a..0000000
--- a/Application/Clavardage/src/controller/TListeningTCPChat.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package controller;
-
-import model.Chat;
-import model.Msg_Text;
-import model.RemoteUser;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.Socket;
-import java.util.Calendar;
-import java.util.Date;
-
-public class TListeningTCPChat extends Thread{
-
- protected Controller controller;
- private Socket socket;
-
- /* CONSTRUCTOR OF ListeningThreadTCPConnection
- * @parametres
- * @param s : String => nom du thread
- * @param myUser : User => utilisateur utilisant ce thread
- * @description
- *
- *
- */
- public TListeningTCPChat(String s,Controller controller,Socket socket) {
- this.controller = controller;
- this.socket=socket;
- }
-
- /* run
- * @description
- *
- *
- *
- */
- public void run() {
- /**** function variables ****/
- BufferedReader in = null;
- String msg = null;
- String input;
- String dateString;
- Date date;
- Calendar date1=Calendar.getInstance();
-
-
- Chat c = null;
-
-
- try {
- in =new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- /************ Check rm user information **********/
- // check data identification from rm user | TO REMOVE IF !=IP
- int rmPortTCP = -1;
- try {
- rmPortTCP = Integer.parseInt(in.readLine());
- } catch (NumberFormatException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- RemoteUser rm = new RemoteUser("Unknown",this.socket.getInetAddress(),rmPortTCP);
-
- int indexRM = controller.myUser.getActiveUserIndexOf(rm);
- // Check if rm is identifiable
- /*System.out.println(rm);
- for(int i=0;i "+rm.getPseudo()+" : "+input);
- Msg_Text message = new Msg_Text(rm,input);
- c.addMessage(message);
- if(controller.activeChat==c) {
- controller.view.notifyNewMessage("("+message.getDate()+")\n"+c.getRemoteUser().getPseudo()+" : "+input);
- }
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- else {
- System.out.println("("+this.controller.myUser.getPseudo()+") Remote User unidentifiable => CLOSING CONNECTION");
- }
-
-
-
-
-
-
-
- }
-
- /* close
- * @description
- *
- * ferme le socket d'écoute TCP pour le chat
- * interrupt TCP listening thread pour le chat
- *
- */
- public void close() {
- try {
- this.socket.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- System.out.println("End of listing thread UDP ("+this.controller.myUser.getPseudo()+")");
- try {
- this.interrupt();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
-}
diff --git a/Application/Clavardage/src/controller/TListeningTCPConnection.java b/Application/Clavardage/src/controller/TListeningTCPConnection.java
deleted file mode 100644
index 7bbab0a..0000000
--- a/Application/Clavardage/src/controller/TListeningTCPConnection.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package controller;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-public class TListeningTCPConnection extends Thread{
-
- protected Controller controller;
- private Socket socket_tcp=null;
- private int nbChat = 0;
-
- /* CONSTRUCTOR OF ListeningThreadTCPConnection
- * @parametres
- * @param s : String => nom du thread
- * @param myUser : User => utilisateur utilisant ce thread
- * @description
- *
- *
- */
- public TListeningTCPConnection(String s,Controller controller) {
- this.controller = controller;
- }
-
- public void accept(ServerSocket servSocket) throws IOException {
- Socket socket_tcp= servSocket.accept();
- this.nbChat++;
- TListeningTCPChat threadtcpchat = new TListeningTCPChat("Chat_of_"+controller.myUser.getPseudo()+"_"+nbChat,controller,socket_tcp);
- threadtcpchat.start();
- threadtcpchat.interrupt();
-
- }
-
- /* run
- * @description
- *
- * écoutes les messages TCP tant que l'utilisateur est actif
- * Traitement
- * Si réception d'une demande, créer un thread pour la conversation
- *
- */
- public void run(){
-
- // Tant que l'utilisateur est actif on attends la demande de nouvelle conversation
- ServerSocket servSocket=null;
- try {
- servSocket = new ServerSocket(controller.myUser.getPortTCP());
- System.out.println("("+this.controller.myUser.getPseudo()+") Server is listening on port "+this.controller.myUser.getPortTCP());
- } catch (IOException e) {
- System.out.println("("+this.controller.myUser.getPseudo()+") Server is not listening on port "+this.controller.myUser.getPortTCP());
- e.printStackTrace();
- }
- while(true) {
- System.out.println("("+this.controller.myUser.getPseudo()+") TCP Server waiting for new connection ...");
-
- try {
- this.accept(servSocket);
- System.out.println("("+this.controller.myUser.getPseudo()+") NEW CONNECTION");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
-
- }
-
- }
-
- /* close
- * @description
- *
- * ferme le socket d'écoute TCO
- * interrupt UDP listening threadS
- *
- */
- public void close() {
- try {
- this.socket_tcp.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- System.out.println("End of listing thread TCP ("+this.controller.myUser.getPseudo()+")");
- try {
- this.interrupt();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
-
-}
-
-
diff --git a/Application/Clavardage/src/controller/TListeningUDP.java b/Application/Clavardage/src/controller/TListeningUDP.java
deleted file mode 100644
index 61dfa06..0000000
--- a/Application/Clavardage/src/controller/TListeningUDP.java
+++ /dev/null
@@ -1,125 +0,0 @@
-package controller;
-
-import model.LocalUser;
-
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-public class TListeningUDP extends Thread{
-
- protected Controller controller;
- private DatagramSocket dgramSocket = null;
-
-
- /* CONSTRUCTOR OF UserListeningThreadUDP
- * @parametres
- * @param s : String => nom du thread
- * @param user : User => utilisateur utilisant ce thread
- * @description
- *
- * Appel du constructeur de la classe hérité
- * Création d'un socket d'écoute UDP
- *
- */
- public TListeningUDP(String s,Controller controller) {
- this.controller = controller;
- try {
- this.dgramSocket = new DatagramSocket(this.controller.myUser.getPortUDPlistening(),this.controller.myUser.getAddIP());
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- }
-
- /* run
- * @description
- *
- * écoutes les messages UDP tant que l'utilisateur est actif
- * Traitement
- * 1) Si demande d'information => envoi ses informations
- * 2) Si réception d'information => ajoute les informations
- *
- */
- public void run(){
-
- // Tant que l'utilisateur est actif on attends les messages des nouveaux utilisateurs et changements des utilisateurs actifs
- while(true) {
-
- // Réception du message
- byte[] buffer = new byte[256];
- DatagramPacket inPacket= new DatagramPacket(buffer, buffer.length);
- try {
- dgramSocket.receive(inPacket);
- } catch (Exception e) {
- e.printStackTrace();
- }
- buffer = inPacket.getData();
-
- // Traitement en fonction du message reçu
- String receiveMsg = new String(buffer);
- String [] tabMsg = receiveMsg.split(":");
-
- // si demande d'information d'un nouvel utilisateur
- if(tabMsg.length==3) {
- InetAddress itsIP = null;
- try {
- itsIP = InetAddress.getByName(tabMsg[0]); // On récupère l'adresse IP de l'utilisateur distant
- } catch (UnknownHostException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- int senderUDPport = Integer.parseInt(tabMsg[1]); // On récupère le port UDP de l'utilisateur distant
-
- String toSend = controller.myUser.getAddIP().getHostAddress()+":"+controller.myUser.getPortTCP()+":"+controller.myUser.getPseudo()+":test";
- DatagramPacket outPacket= new DatagramPacket(toSend.getBytes(), toSend.length(),itsIP, senderUDPport);
-
- try {
- dgramSocket.send(outPacket);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- // Si un nouvel utilisateur passe en mode actif ou changement d'information
- else {
- try {
- // On récupère l'adresse IP et le port TCP de l'utilisateur distant et ajout à la liste de l'utilisateur utilisant ce thread
- controller.myUser.addRemoteUser(InetAddress.getByName(tabMsg[0]),Integer.parseInt(tabMsg[1]),tabMsg[2]);
- } catch (NumberFormatException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- if(controller.interfaceRunning) {
- controller.view.updateActiveUsers();
- }
- }
-
-
- }
-
-
- }
-
- /* close
- * @description
- *
- * Ferme le socket d'écoute UDP
- * Interrompt le thread d'écoute UDP
- *
- */
- public void close() {
- this.dgramSocket.close();
- System.out.println("End of listing thread UDP ("+this.controller.myUser.getPseudo()+")");
- try {
- this.interrupt();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
-}
diff --git a/Application/Clavardage/src/model/Chat.java b/Application/Clavardage/src/model/Chat.java
deleted file mode 100644
index d1901a5..0000000
--- a/Application/Clavardage/src/model/Chat.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package model;
-
-import java.io.IOException;
-import java.net.Socket;
-import java.util.ArrayList;
-
-public class Chat {
-
- /*** ATTRIBUTS ***/
- private RemoteUser remoteUser;
- private ArrayList messages = new ArrayList();
- private Socket userSocket;
- private Boolean active = false;
-
- /**
- * Constructor of Chat (local)
- * @parametres
- * @param remoteUser : remoteUser => référence de l'utilisateur distant
- * @description
- *
- *
- *
- */
- public Chat(RemoteUser rm) {
- this.remoteUser=rm;
- }
-
- /*** GETTERS ***/
- public RemoteUser getRemoteUser() {
- return remoteUser;
- }
- public ArrayList getMessages() {
- return messages;
- }
- public Socket getUserSocket() {
- return userSocket;
- }
- public Boolean getActive() {
- return active;
- }
-
- /*** SETTERS ***/
- public void setRemoteUser(RemoteUser rm) {
- this.remoteUser = rm;
- }
- public void setSocket(Socket link) {
- this.userSocket = link;
- }
- public void addMessage(Message msg) {
- this.messages.add(msg);
- }
- public void addListMessage( ArrayList msg) {
- this.messages=msg;
- }
- public void activate() {
- this.active = true;
- }
-
- public void close() {
- this.active = false;
- try {
- this.userSocket.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- }
-
-}
diff --git a/Application/Clavardage/src/model/LocalUser.java b/Application/Clavardage/src/model/LocalUser.java
deleted file mode 100644
index dae9dbc..0000000
--- a/Application/Clavardage/src/model/LocalUser.java
+++ /dev/null
@@ -1,149 +0,0 @@
-package model;
-
-import java.net.InetAddress;
-import java.util.ArrayList;
-
-
-public class LocalUser extends User{
-
-
- /*** ATTRIBUTS ***/
- private int portUDPsend;
- private int portUDPlistening;
- private ArrayList remoteUsersList = new ArrayList(); // listes des utilisateurs actifs
- private ArrayList chats = new ArrayList();
-
- /**
- * Constructor of LocalUser
- * @parametres
- * @param pseudo : String
- * @param addIP : InetAddress
- * @param portUDPsend : int => le numéro de port pour envoyé ces informations lors d'un changements ou d'une nouvelle connexion
- * @param portUDPlistening : int => le numéro de port pour recevoir les informations des nouveaux utilisateurs ou les changements
- * @param portTCP : int => le numéro de port pour commencer une nouvelle conversation
- * @description
- *
- *
- *
- */
- public LocalUser(String pseudo,InetAddress addIP,int portUDPsend,int portUDPlistening,int portTCP){
- super(pseudo,addIP,portTCP);
- this.portUDPsend = portUDPsend;
- this.portUDPlistening = portUDPlistening;
- }
-
- /*** GETTERS ***/
- public int getPortUDPsend() {
- return portUDPsend;
- }
- public int getPortUDPlistening() {
- return portUDPlistening;
- }
- public ArrayList getRemoteUsersList() {
- return remoteUsersList;
- }
- public ArrayList getChats() {
- return chats;
- }
-
- /*** SETTERS ***/
- public void setPortUDPsend(int portUDPsend) {
- this.portUDPsend = portUDPsend;
- }
- public void setPortUDPlistening(int portUDPlistening) {
- this.portUDPlistening = portUDPlistening;
- }
-
-
-
- /**
- * @parameters
- * @param remoteUserIP : InetAddress => l'adresse IP de l'utilisateur distant
- * @param remoteUserPortTCP : int => le numéro de port TCP d'écoute de l'utilisateur distant
- * @param remoteUserPseudo : String => le pseudo de l'utilisateur distant
- *
- * Ajout ou mise à jour l'utilisateur distant dans notre liste d'utilisateur distant
- *
- */
- public void addRemoteUser(InetAddress remoteUserIP, int remoteUserPortTCP,String remoteUserPseudo) {
- RemoteUser tmpRemoteUser = new RemoteUser(remoteUserPseudo,remoteUserIP,remoteUserPortTCP);
- int index = this.remoteUsersList.indexOf(tmpRemoteUser);
- if(index!=-1) {
- System.out.println("("+this.pseudo+") "+"MAJ, IP(port) : "+remoteUserPseudo+" => "+remoteUserIP+"("+remoteUserPortTCP+")");
- this.remoteUsersList.get(index).setAddIP(remoteUserIP);
- this.remoteUsersList.get(index).setPortTCP(remoteUserPortTCP);
- this.remoteUsersList.get(index).setPseudo(remoteUserPseudo);
- }
- else {
- System.out.println("("+this.pseudo+") "+"Add new user IP(port) : "+remoteUserPseudo+" => "+remoteUserIP+"("+remoteUserPortTCP+")");
- this.remoteUsersList.add(tmpRemoteUser);
- }
- /*
- int i = getChatIndexOf(tmpRemoteUser);
- if(i!=-1) {
- chats.get(i).setRemoteUser(tmpRemoteUser);
- }*/
- }
-
- public Chat addChats(RemoteUser rm) {
- Chat newChat= new Chat(rm);
-
- if(getChatIndexOf(rm)==-1) {
- this.getChats().add(newChat);
- }
-
- return newChat;
- }
-
-
- public int getChatIndexOf(RemoteUser rm) {
- int index=0;
-
- Boolean found = false;
- while(index
- *
- *
- */
- public Message(User autor) {
- this.autor = autor;
- DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
- this.date = dateFormat.format(new Date());
- }
- public Message(User autor, String date) {
- this.autor = autor;
- this.date = date;
- }
- /*** GETTERS ***/
- public String getDate() {
- return date;
- }
- public User getAutor() {
- return autor;
- }
-
- /*** SETTERS ***/
- public void setAutorIP(User autor) {
- this.autor = autor;
- }
- public void setDate(String date) {
- this.date=date;
- }
-
-
- public abstract Object getMessage();
-}
diff --git a/Application/Clavardage/src/model/Msg_Text.java b/Application/Clavardage/src/model/Msg_Text.java
deleted file mode 100644
index dc428f6..0000000
--- a/Application/Clavardage/src/model/Msg_Text.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package model;
-
-import java.net.InetAddress;
-
-public class Msg_Text extends Message{
-
- /*** ATTRIBUT ***/
- private String text;
-
- public Msg_Text(User autor,String text) {
- super(autor);
- this.text = text;
- }
- public Msg_Text(User autor,String date, String text) {
- super(autor,date);
- this.text = text;
- }
-
- @Override
- public String getMessage() {
- return this.text;
- }
-
-
-
-}
diff --git a/Application/Clavardage/src/model/RemoteUser.java b/Application/Clavardage/src/model/RemoteUser.java
deleted file mode 100644
index 003a2b5..0000000
--- a/Application/Clavardage/src/model/RemoteUser.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package model;
-
-import java.net.InetAddress;
-
-public class RemoteUser extends User{
-
- public RemoteUser(String pseudo, InetAddress addIP, int portTCP) {
- super(pseudo, addIP, portTCP);
- }
-
- @Override
- public String toString() {
- return "RemoteUser [pseudo=" + pseudo + ", addIP=" + addIP + ", portTCP=" + portTCP + ", IPcode=" + IPcode
- + "]";
- }
-
-
-}
diff --git a/Application/Clavardage/src/model/User.java b/Application/Clavardage/src/model/User.java
deleted file mode 100644
index 6a39a55..0000000
--- a/Application/Clavardage/src/model/User.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package model;
-
-import java.net.*;
-
-public abstract class User {
-
-
- /*** ATTRIBUTS ***/
- protected String pseudo;
- protected InetAddress addIP;
- protected int portTCP;
- protected int IPcode;
-
- /**
- * Constructor of User (local)
- * @parametres
- * @param pseudo : String
- * @param addIP : InetAddress
- * @param portTCP : int => le numéro de port pour commencer une nouvelle conversation
- * @description
- *
- *
- *
- */
- public User(String pseudo,InetAddress addIP,int portTCP){
- this.pseudo = pseudo;
- this.addIP=addIP;
- this.portTCP=portTCP;
- this.IPcode=hashCode();
- }
-
-
- /*** GETTERS ***/
- public int getIPcode() {
- return IPcode;
- }
- public String getPseudo() {
- return pseudo;
- }
- public InetAddress getAddIP() {
- return addIP;
- }
- public int getPortTCP() {
- return portTCP;
- }
-
-
- /*** SETTERS ***/
- public void setPseudo(String pseudo) {
- this.pseudo = pseudo;
- }
- public void setAddIP(InetAddress addIP) {
- this.addIP = addIP;
- }
- public void setPortTCP(int portTCP) {
- this.portTCP = portTCP;
- }
-
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- String ip=addIP.getHostAddress();
- result = prime * result + ((ip == null) ? 0 : ip.hashCode());
- result = prime * result + portTCP;
- return result;
- }
-
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- User other = (User) obj;
- if (addIP == null) {
- if (other.addIP != null)
- return false;
- } else if (!addIP.equals(other.addIP))
- return false;
- if (portTCP != other.portTCP)
- return false;
- return true;
- }
-
-
- @Override
- public String toString() {
- return "User [pseudo=" + pseudo + ", addIP=" + addIP.getHostAddress() + ", portTCP=" + portTCP + ", IPcode=" + IPcode + "]";
- }
-
-
-
-
-
-
-
-
-
-
-
-}
diff --git a/Application/Clavardage/src/view/Interface.java b/Application/Clavardage/src/view/Interface.java
deleted file mode 100644
index 6ab128d..0000000
--- a/Application/Clavardage/src/view/Interface.java
+++ /dev/null
@@ -1,285 +0,0 @@
-package view;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.io.IOException;
-
-import controller.Controller;
-
-public class Interface extends JFrame implements ActionListener, WindowListener {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L; //JFrame stuff
-
- public Controller controller;
-
- public JLabel Pseudolabel;
- public JLabel ChangePseudolabel;
- public JTextField ChangePseudotextField;
-
- public JTextArea MessagetextArea;
- public JTextField MessagetextField;
- public JScrollPane scrollpane;
-
- public JButton RemoteUserButton;
- public JComboBox RemoteUserbox;
- public JButton CloseConversationButton;
-
- //Specifies the look and feel to use. Valid values:
- //null (use the default), "Metal", "System", "Motif", "GTK+"
- final static String LOOKANDFEEL = "System";
-
- public Interface(Controller controller) {
- this.controller = controller;
- this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- this.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent e) {
- System.out.println("Window closing");
- }
- });
-
- }
-
- public Component createComponents() {
-
- //Pseudo setup
- JPanel changePseudoPanel = new JPanel(new GridLayout(1, 0));
- ChangePseudolabel = new JLabel("Change nickname : ");
- changePseudoPanel.add(ChangePseudolabel);
- ChangePseudotextField = new JTextField();
- ChangePseudotextField.setColumns(10);
- ChangePseudotextField.addActionListener(this);
- changePseudoPanel.add(ChangePseudotextField);
-
- Pseudolabel = new JLabel("Nickname : "+controller.getMyUser().getPseudo());
- Pseudolabel.setLabelFor(ChangePseudotextField);
-
-
-
- //Remote user list setup
- RemoteUserButton = new JButton("Start session");
- RemoteUserButton.addActionListener(this);
-
-
- // Remote user list
- //Converts the Userlist to a Pseudotab for treatment in actionPerformed
- String[] pseudotab = controller.askUpdateActiveUsers();
- RemoteUserbox = new JComboBox(pseudotab);
- RemoteUserbox.setEditable(true);
- RemoteUserbox.addActionListener(this);
- RemoteUserbox.setVisible(false);
-
- // Close session
- CloseConversationButton = new JButton("Close session");
- CloseConversationButton.addActionListener(this);
- CloseConversationButton.setVisible(false);
-
- JPanel userListsPanel = new JPanel(new GridLayout(1, 0));
-
- userListsPanel.add(RemoteUserButton);
- userListsPanel.add(RemoteUserbox);
- userListsPanel.add(CloseConversationButton);
-
-
- //Messages setup
- MessagetextField = new JTextField();
- MessagetextField.setColumns(10);
- MessagetextField.addActionListener(this);
- MessagetextArea = new JTextArea("Chat");
- scrollpane = new JScrollPane();
- scrollpane.getViewport().add(MessagetextArea);
- scrollpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
- scrollpane.setPreferredSize(new Dimension(600,60));
- MessagetextField.setVisible(false);
- MessagetextArea.setVisible(false);
- scrollpane.setVisible(false);
- // Create a placeholder on JTextField
- MessagetextField.addFocusListener(new FocusListener() {
- @Override
- public void focusGained(FocusEvent e) {
- if (MessagetextField.getText().equals("Your message")) {
- MessagetextField.setText("");
- MessagetextField.setForeground(Color.BLACK);
- }
- }
- @Override
- public void focusLost(FocusEvent e) {
- if (MessagetextField.getText().isEmpty()) {
- MessagetextField.setForeground(Color.GRAY);
- MessagetextField.setText("Your message");
- }
- }
- });
-
-
- /*
- * An easy way to put space between a top-level container
- * and its contents is to put the contents in a JPanel
- * that has an "empty" border.
- */
- JPanel header = new JPanel(new GridLayout(0, 1));
- header.add(Pseudolabel);
- header.add(changePseudoPanel);
- header.add(userListsPanel);
-
- JPanel pane = new JPanel(new BorderLayout());
- pane.add(header,BorderLayout.NORTH);
- pane.add(scrollpane,BorderLayout.CENTER);
- pane.add(MessagetextField,BorderLayout.SOUTH);
- pane.setBorder(BorderFactory.createEmptyBorder(
- 30, //top
- 30, //left
- 10, //bottom
- 30) //right
- );
-
- return pane;
- }
-
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == ChangePseudotextField) { //Changing pseudo
- String Textinput = ChangePseudotextField.getText();
- Pseudolabel.setText("Your current username is: " + Textinput);
-
- try {
- controller.changePseudo();
- } catch (IOException e1) {
- System.out.println("Error in change pseudo\n");
- e1.printStackTrace();
- }
- }else if(e.getSource() == MessagetextField){ //Messages
- String Textinput = MessagetextField.getText();
- MessagetextArea.setText(MessagetextArea.getText() + "\n" + controller.getMyUser().getPseudo() + " : " + Textinput );
- MessagetextField.setText("");
- controller.askToSend(Textinput); // ask to send to controller
-
- }else if(e.getSource() == RemoteUserButton) { //Shows remote user list
- RemoteUserbox.setVisible(true);
- }else if(e.getSource() == CloseConversationButton) {
- controller.askCloseSession();
- MessagetextArea.setVisible(false);
- scrollpane.setVisible(false);
- MessagetextField.setVisible(false);
- CloseConversationButton.setVisible(false);
- }else if(e.getSource() == RemoteUserbox){ // Choice in remote user list
-
- //JComboBox cb = (JComboBox)e.getSource(); //Casts obscurs pour récupérer le numéro du user dans la liste
- int selectedUsernb = RemoteUserbox.getSelectedIndex();
- //String.valueOf(((String) cb.getSelectedItem()).charAt(1)));
-
- // start or switch chat => get history
- String history = controller.askOpenSession(selectedUsernb);
- // display it
- MessagetextArea.setText(history);
- MessagetextField.setVisible(true);
- scrollpane.setVisible(true);
- MessagetextArea.setVisible(true);
- CloseConversationButton.setVisible(true);
- }
- }
-
- private static void initLookAndFeel() {
- // Swing allows you to specify which look and feel your program uses-
- // -Java,
- // GTK+, Windows, and so on as shown below.
- String lookAndFeel = null;
-
- if (LOOKANDFEEL != null) {
- if (LOOKANDFEEL.equals("Metal")) {
- lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
- } else if (LOOKANDFEEL.equals("System")) {
- lookAndFeel = UIManager.getSystemLookAndFeelClassName();
- } else if (LOOKANDFEEL.equals("Motif")) {
- lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
- } else if (LOOKANDFEEL.equals("GTK+")) { //new in 1.4.2
- lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
- } else {
- System.err.println("Unexpected value of LOOKANDFEEL specified: " + LOOKANDFEEL);
- lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
- }
- try {UIManager.setLookAndFeel(lookAndFeel);
- } catch (ClassNotFoundException e) {
- System.err.println("Couldn't find class for specified look and feel:" + lookAndFeel);
- System.err.println("Did you include the L&F library in the class path?");
- System.err.println("Using the default look and feel.");
- } catch (UnsupportedLookAndFeelException e) {
- System.err.println("Can't use the specified look and feel (" + lookAndFeel+ ") on this platform.");
- System.err.println("Using the default look and feel.");
- } catch (Exception e) {
- System.err.println("Couldn't get specified look and feel (" + lookAndFeel + "), for some reason.");
- System.err.println("Using the default look and feel.");
- e.printStackTrace();
- }
- }
- }
-
- /**
- * Create the GUI and show it. For thread safety,
- * this method should be invoked from the
- * event-dispatching thread.
- */
- public static Interface createAndShowGUI(Controller controller) {
- //Set the look and feel.
- initLookAndFeel();
-
- //Make sure we have nice window decorations.
- JFrame.setDefaultLookAndFeelDecorated(true);
-
- //Create and set up the window.
- JFrame frame = new JFrame("Clavardage App");
- frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- Interface app = new Interface(controller);
- Component contents = app.createComponents();
- frame.getContentPane().add(contents, BorderLayout.CENTER);
- frame.setPreferredSize(new Dimension(400,300));
-
- //Ends all running background tasks upon closing the window
- frame.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent windowEvent) {
- System.out.println("("+controller.getMyUser().getPseudo()+") Window has been closed");
- controller.askForClose();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- });
-
- //Display the window.
- frame.pack();
- frame.setVisible(true);
-
- return app;
- }
-
- public void windowOpened(WindowEvent e) {} //Had to implement it for WindowListener
- public void windowActivated(WindowEvent e) {}
- public void windowIconified(WindowEvent e) {}
- public void windowDeiconified(WindowEvent e) {}
- public void windowDeactivated(WindowEvent e) {}
- public void windowClosed(WindowEvent e) {}
- public void windowClosing(WindowEvent e) {}
-
-
- public void notifyNewMessage(String msg) {
- MessagetextArea.setText(MessagetextArea.getText() + "\n" + msg);
-
- }
-
- public void updateActiveUsers() {
- DefaultComboBoxModel model = new DefaultComboBoxModel<>( controller.askUpdateActiveUsers() );
- RemoteUserbox.setModel( model );
- }
- /*
- public static void main(String[] args) throws IOException {
- //Schedule a job for the event-dispatching thread:
- //creating and showing this application’s GUI.
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }*/
-}
\ No newline at end of file
diff --git a/Application/Clavardage/src/websocket/Appel.java b/Application/Clavardage/src/websocket/Appel.java
deleted file mode 100644
index f4b6eeb..0000000
--- a/Application/Clavardage/src/websocket/Appel.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package websocket;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import javax.websocket.ContainerProvider;
-import javax.websocket.DeploymentException;
-import javax.websocket.Session;
-import javax.websocket.WebSocketContainer;
-
-
-public class Appel {
-
- private WebSocketContainer container;
- private Client client;
-
- public void test() {
- this.container= ContainerProvider.getWebSocketContainer();
- this.client=new Client();
-
- Session session=null;
- try {
- session=this.container.connectToServer(this.client, new URI ("ws://localhost:8082/WebSocket2/hello"));
- } catch (DeploymentException | IOException | URISyntaxException e) {
- e.printStackTrace();
- System.out.println("pb avec le connect");
- }
- try {
- this.client.onOpen(session, null);
- this.client.sendMessage("hello from client");
- } catch (IOException e) {
- System.out.println("pb avec le sendMessage");
- e.printStackTrace();
- }
- }
-
-
-}
diff --git a/Application/Clavardage/src/websocket/Centralized.java b/Application/Clavardage/src/websocket/Centralized.java
deleted file mode 100644
index 8add15a..0000000
--- a/Application/Clavardage/src/websocket/Centralized.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package websocket;
-
-public class Centralized {
-
-}
diff --git a/Application/Clavardage/src/websocket/Client.java b/Application/Clavardage/src/websocket/Client.java
deleted file mode 100644
index da2eb1a..0000000
--- a/Application/Clavardage/src/websocket/Client.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package websocket;
-
-import java.io.IOException;
-
-import javax.websocket.*;
-
-public class Client extends Endpoint{
- private Session session;
-
- @Override
- public void onOpen (Session session, EndpointConfig config) {
- this.session=session;
- this.session.addMessageHandler(new MessageHandler.Whole() {
- @Override
- public void onMessage (String msg) {
- System.out.println("msg recu:"+msg);
- };}
- );
- }
-
- public void sendMessage(String msg) throws IOException {
- this.session.getBasicRemote().sendText(msg);
- }
-
-}
-