diff --git a/Implementation/src/ChatApp.class b/Implementation/src/ChatApp.class new file mode 100644 index 0000000..17214bc Binary files /dev/null and b/Implementation/src/ChatApp.class differ diff --git a/Implementation/src/ChatApp.java b/Implementation/src/ChatApp.java index 1fecbb9..8493817 100644 --- a/Implementation/src/ChatApp.java +++ b/Implementation/src/ChatApp.java @@ -5,6 +5,7 @@ import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.Arrays; public class ChatApp { @@ -40,12 +41,40 @@ public class ChatApp { DatagramPacket packet = new DatagramPacket( buffer, buffer.length, InetAddress.getLoopbackAddress(), 1234 ); socket.send(packet); socket.close(); - System.out.println("Chat app -> " + broadcastMessage); + System.out.println(this.me.getPseudo() + " envoie : " + broadcastMessage); } + public static Utilisateur stringToUtilisateur(String s){ + String lines[] = s.split("|"); + String name = ""; + Integer port = 0; + String ip = "" ; + for (String line : lines ){ + String mots[] = line.split(" "); + if (mots[0]=="pseudo"){ + name=mots[1]; + } + if(mots[0]=="port") + { + port=Integer.parseInt(mots[1]); + } + if(mots[0]=="ip") + { + ip=mots[1]; + } + } + Utilisateur user = null; + try { + user = new Utilisateur(name,port,InetAddress.getByName(ip)); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + return user; + } public static void main (String[] args) { //Integer p = 2345 ; ChatApp app = new ChatApp(args[0],Integer.parseInt(args[1])) ; + try { app.connexion(); } catch (IOException e) { @@ -66,8 +95,14 @@ public class ChatApp { } catch (IOException e) { e.printStackTrace(); } - System.out.println(data); - } + String received = new String(data.getData(), 0, data.getLength()); + System.out.println(app.me.getPseudo() + " reçoit : " + received); + app.actifUsers.add(stringToUtilisateur(received)); + for(Utilisateur elem: app.actifUsers) + { + System.out.println (elem.toString()); + } } + } } diff --git a/Implementation/src/Utilisateur.class b/Implementation/src/Utilisateur.class new file mode 100644 index 0000000..778301c Binary files /dev/null and b/Implementation/src/Utilisateur.class differ diff --git a/Implementation/src/Utilisateur.java b/Implementation/src/Utilisateur.java index 6c292a2..06951f4 100644 --- a/Implementation/src/Utilisateur.java +++ b/Implementation/src/Utilisateur.java @@ -33,9 +33,9 @@ public class Utilisateur { public String toString(){ String s = ""; - s+="pseudo " + this.pseudo + " \n"; - s+="port " + (this.port).toString() + "\n"; - s+="id " + (this.ip).toString() + "\n"; + s+="pseudo " + this.pseudo + " | "; + s+="port " + (this.port).toString() + " | "; + s+="ip " + (this.ip).toString() + " | "; return s; }