diff --git a/Application/Clavardage/src/controller/Controller.java b/Application/Clavardage/src/controller/Controller.java index 6fdf8ca..d2f32b3 100644 --- a/Application/Clavardage/src/controller/Controller.java +++ b/Application/Clavardage/src/controller/Controller.java @@ -337,12 +337,16 @@ public class Controller { /*** 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) + sendMessage(new Msg_Text(myUser.getAddIP(),Integer.toString(myUser.getPortTCP())),c); }catch(IOException e) { System.out.println("Error linking to TCP server of "+ c.getRemoteUser().getPortTCP()); } - c.setSocket(link); + /*** recup history and put it in model ***/ /* @@ -374,7 +378,7 @@ public class Controller { // Look for history int nbMessage = c.getMessages().size(); for(int i=0;i CLOSING CONNECTION"); } - */ + + /*** listening tcp message from rm until session is close ***/ + try { - System.out.println("("+this.controller.myUser.getPseudo()+") WAIT FOR NEW MESSAGE FROM ");//+rm.getPseudo()); - in =new BufferedReader(new InputStreamReader(this.socket.getInputStream())); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - try { + System.out.println("("+this.controller.myUser.getPseudo()+") WAIT FOR NEW MESSAGE FROM "+rm.getPseudo()); + while (!(input=in.readLine()).equals("end")/* && c.getActive()*/) { - System.out.println("("+this.controller.myUser.getPseudo()+") recoit : "+input); - //c.addMessage(new Msg_Text(rm.getAddIP(),input)); + System.out.println("("+this.controller.myUser.getPseudo()+") recoit => "+rm.getPseudo()+" : "+input); + c.addMessage(new Msg_Text(rm.getAddIP(),input)); // TODO Prévenir l'interface de la réception d'un nouveau message + controller.view.notifyNewMessage(); } } catch (IOException e) { diff --git a/Application/Clavardage/src/model/LocalUser.java b/Application/Clavardage/src/model/LocalUser.java index afd79c7..e22672b 100644 --- a/Application/Clavardage/src/model/LocalUser.java +++ b/Application/Clavardage/src/model/LocalUser.java @@ -112,8 +112,15 @@ public class LocalUser extends User{ public int getActiveUserIndexOf(RemoteUser rm) { int index = 0; Boolean found = false; + //System.out.println(rm); while(index