diff --git a/src/GraphiquePackage/FichCom.form b/src/GraphiquePackage/FichCom.form index 4ab3758..7a04a78 100644 --- a/src/GraphiquePackage/FichCom.form +++ b/src/GraphiquePackage/FichCom.form @@ -23,20 +23,26 @@ - - - - - + + + + + - - - - - + + + + + + + + + - + + + @@ -45,12 +51,14 @@ - - - - + + + + + + - + @@ -84,5 +92,13 @@ + + + + + + + + diff --git a/src/GraphiquePackage/FichCom.java b/src/GraphiquePackage/FichCom.java index 066609b..c4826da 100644 --- a/src/GraphiquePackage/FichCom.java +++ b/src/GraphiquePackage/FichCom.java @@ -5,6 +5,8 @@ */ package GraphiquePackage; +import SourcePackage.Main; + /** * * @author elyes @@ -14,9 +16,13 @@ public class FichCom extends javax.swing.JDialog { /** * Creates new form FichCom */ - public FichCom(java.awt.Dialog parent, boolean modal) { + + private static int portDest; + + public FichCom(java.awt.Dialog parent, boolean modal, int port ) { super(parent, modal); initComponents(); + portDest = port ; } /** @@ -32,6 +38,7 @@ private void initComponents() { jButton1 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); listMsg = new javax.swing.JTextArea(); + msgWrote = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -48,42 +55,60 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { listMsg.setRows(5); jScrollPane1.setViewportView(listMsg); + msgWrote.setText("Ecrire message..."); + msgWrote.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + msgWroteActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(32, 32, 32) - .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() - .addGap(24, 24, 24) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(30, 30, 30) - .addComponent(jButton1))) - .addContainerGap(93, Short.MAX_VALUE)) + .addContainerGap() + .addComponent(msgWrote, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(32, 32, 32) + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGap(21, 21, 21) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(89, 89, 89)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(83, 83, 83) .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGap(26, 26, 26) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(39, 39, 39) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(82, 82, 82)) + .addComponent(msgWrote, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(40, Short.MAX_VALUE)) ); pack(); }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - - + + Main.user.sendMessageTCP(msgWrote.getText(),"", portDest,false); + this.listMsg.setText(listMsg.getText().concat("\n \t "+ msgWrote.getText())); }//GEN-LAST:event_jButton1ActionPerformed + private void msgWroteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_msgWroteActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_msgWroteActionPerformed + /** * @param args the command line arguments */ @@ -115,7 +140,7 @@ public static void main(String args[]) { /* Create and display the dialog */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { - FichCom dialog = new FichCom(new javax.swing.JDialog(), true); + FichCom dialog = new FichCom(new javax.swing.JDialog(), true, 0); dialog.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { @@ -138,5 +163,6 @@ public void setListMsg(String msg){ private javax.swing.JLabel jLabel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea listMsg; + private javax.swing.JTextField msgWrote; // End of variables declaration//GEN-END:variables } diff --git a/src/GraphiquePackage/FichMenu.form b/src/GraphiquePackage/FichMenu.form index 7b75175..3c08a48 100644 --- a/src/GraphiquePackage/FichMenu.form +++ b/src/GraphiquePackage/FichMenu.form @@ -23,6 +23,25 @@ + + + + + + + + + + + + + + + + + + + @@ -30,27 +49,9 @@ - - - - - - - - - - - - - - - - - - - + @@ -71,13 +72,15 @@ - - + + + + + - - + @@ -125,12 +128,12 @@ - + - + diff --git a/src/GraphiquePackage/FichMenu.java b/src/GraphiquePackage/FichMenu.java index 92ecf4a..d6848a1 100644 --- a/src/GraphiquePackage/FichMenu.java +++ b/src/GraphiquePackage/FichMenu.java @@ -6,6 +6,8 @@ package GraphiquePackage; import SourcePackage.Main; +import static java.lang.Integer.parseInt; +import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JTextField; @@ -20,13 +22,21 @@ public class FichMenu extends javax.swing.JDialog { */ FichCom fichCom; + public FichMenu(FichAccueil parent, boolean modal) { super(parent, modal); initComponents(); MonPseudo.setText(parent.getPseudo()); + + ThreadPrintListUser threadPrint = new ThreadPrintListUser("thread print"); + threadPrint.start(); + } + public static void setListUser(String liste){ + listUser.setText(liste); + } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always @@ -42,7 +52,7 @@ private void initComponents() { MonPseudo = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); - jTextField1 = new javax.swing.JTextField(); + pseudoEntry = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -68,10 +78,10 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); - jTextField1.setText("A qui parler ? entrer pseudo"); - jTextField1.addActionListener(new java.awt.event.ActionListener() { + pseudoEntry.setText("A qui parler ? entrer pseudo"); + pseudoEntry.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - jTextField1ActionPerformed(evt); + pseudoEntryActionPerformed(evt); } }); @@ -79,29 +89,30 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jLabel3) + .addGap(18, 18, 18) + .addComponent(MonPseudo) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 670, Short.MAX_VALUE) + .addComponent(jButton1)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(listUser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(18, 18, 18) + .addComponent(jButton2) + .addGap(37, 37, 37))) + .addGap(44, 44, 44)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(jLabel3) - .addGap(18, 18, 18) - .addComponent(MonPseudo) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 658, Short.MAX_VALUE) - .addComponent(jButton1)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(listUser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(18, 18, 18) - .addComponent(jButton2) - .addGap(37, 37, 37))) - .addGap(44, 44, 44)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(pseudoEntry, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(22, 22, 22)))) ); layout.setVerticalGroup( @@ -116,12 +127,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGap(18, 18, 18) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(36, 36, 36) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(listUser, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jButton2)) - .addContainerGap(130, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(pseudoEntry, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(37, 37, 37) + .addComponent(jButton2)) + .addComponent(listUser, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(198, Short.MAX_VALUE)) ); pack(); @@ -132,25 +144,40 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS listUser.setText(Main.user.getListUser().toString()); }//GEN-LAST:event_jButton1ActionPerformed - private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed + private void pseudoEntryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pseudoEntryActionPerformed // TODO add your handling code here: - }//GEN-LAST:event_jTextField1ActionPerformed + }//GEN-LAST:event_pseudoEntryActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - fichCom = new FichCom(this,false); + + fichCom = new FichCom(this,false,0); this.fichCom.setVisible(true); Main.user.addFichCom(fichCom); + String[] info = Main.user.getListUser().get(pseudoEntry.getText()).toString().split("-"); + System.out.println(">>>>>>>>>>>>>>>>>>>>" + info[0]); + Main.user.sendMessageTCP("je me co",info[0],parseInt(info[1]), true); + + }//GEN-LAST:event_jButton2ActionPerformed - - public void openWindow(){ - fichCom = new FichCom(this,false); + public void majButton(String name){ + JButton button = new JButton(name); + button.setVisible(true); + } + + public void openWindow(int port){ + fichCom = new FichCom(this,false,port); this.fichCom.setVisible(true); Main.user.addFichCom(fichCom); } /** * @param args the command line arguments */ + + public String getPseudo(){ + return ((FichAccueil)this.getParent()).getPseudo(); + } + public static void main(String args[]) { /* Set the Nimbus look and feel */ // @@ -201,7 +228,7 @@ public void windowClosing(java.awt.event.WindowEvent e) { private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel3; - private javax.swing.JTextField jTextField1; private static javax.swing.JLabel listUser; + private javax.swing.JTextField pseudoEntry; // End of variables declaration//GEN-END:variables } diff --git a/src/GraphiquePackage/ThreadPrintListUser.java b/src/GraphiquePackage/ThreadPrintListUser.java new file mode 100644 index 0000000..16129cb --- /dev/null +++ b/src/GraphiquePackage/ThreadPrintListUser.java @@ -0,0 +1,34 @@ +package GraphiquePackage; + +import SourcePackage.Main; +import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class ThreadPrintListUser extends Thread { + + public ThreadPrintListUser(String name){ + super(name); + + } + + @Override + public void run(){ + + HashMap listUser2 = Main.getUserList(); + + // System.out.println(listUser.toString()); + + while(true) { + try { + sleep(1000); + FichMenu.setListUser(Main.user.getListUser().toString()); + + } catch (InterruptedException ex) { + Logger.getLogger(ThreadPrintListUser.class.getName()).log(Level.SEVERE, null, ex); + } + + } + } + +} diff --git a/src/SourcePackage/Main.java b/src/SourcePackage/Main.java index 9d03dbb..5771221 100644 --- a/src/SourcePackage/Main.java +++ b/src/SourcePackage/Main.java @@ -2,6 +2,7 @@ import GraphiquePackage.FichAccueil; import GraphiquePackage.FichMenu; +import java.util.HashMap; import java.util.Scanner; public class Main { @@ -26,11 +27,15 @@ public static void setFichMenu(FichMenu fichMenu1){ fichMenu = fichMenu1; } - public static void openFich(){ - fichMenu.openWindow(); + public static void openFich(int port){ + fichMenu.openWindow(port); } - public User getUser(){ + public static User getUser(){ return user; } + + public static HashMap getUserList(){ + return user.getListUser(); + } } \ No newline at end of file diff --git a/src/SourcePackage/SetThreadCommunication.java b/src/SourcePackage/SetThreadCommunication.java index 7daf544..d8c8577 100644 --- a/src/SourcePackage/SetThreadCommunication.java +++ b/src/SourcePackage/SetThreadCommunication.java @@ -4,14 +4,10 @@ public class SetThreadCommunication { private ThreadReceiveTCPFinal threadReceiveTCP; - private ThreadSendTCPFinal threadSendTCP; public SetThreadCommunication(Socket client2Socket) { threadReceiveTCP = new ThreadReceiveTCPFinal(client2Socket); - threadSendTCP = new ThreadSendTCPFinal("Send",client2Socket,false); - threadReceiveTCP.start(); - threadSendTCP.start(); } } diff --git a/src/SourcePackage/ThreadAcceptTCP.java b/src/SourcePackage/ThreadAcceptTCP.java index 0b56a73..9cb268d 100644 --- a/src/SourcePackage/ThreadAcceptTCP.java +++ b/src/SourcePackage/ThreadAcceptTCP.java @@ -9,9 +9,6 @@ public class ThreadAcceptTCP extends Thread{ - private ThreadReceiveTCPFinal threadReceiveTCP = null; - private ThreadSendTCPFinal threadSendTCP = null; - private HashMap listSocket; private HashMap listThreadToSocket; private ServerSocket client1Socket ; @@ -19,7 +16,6 @@ public class ThreadAcceptTCP extends Thread{ public ThreadAcceptTCP(String name) { super(name); - listSocket = new HashMap<>(); listThreadToSocket = new HashMap<>(); try { client1Socket = new ServerSocket(Main.user.getPort()); @@ -37,8 +33,10 @@ public void run() { System.out.println("Une connexion en attente ... "); client2Socket = client1Socket.accept(); System.out.println("connexion effectuée "); - Main.openFich(); - listSocket.put(client2Socket.getPort(), client2Socket); // dans l'hash map des socket on va rajouter un socket du client qui se connecte + Main.openFich(client2Socket.getPort()); + System.out.println("port : " + client2Socket.getPort()); + + Main.user.putListSocket(client2Socket); // dans l'hash map des socket on va rajouter un socket du client qui se connecte listThreadToSocket.put(client2Socket, new SetThreadCommunication(client2Socket)); //liste des threads } } diff --git a/src/SourcePackage/ThreadMenu.java b/src/SourcePackage/ThreadMenu.java deleted file mode 100644 index 0f71ac6..0000000 --- a/src/SourcePackage/ThreadMenu.java +++ /dev/null @@ -1,49 +0,0 @@ -package SourcePackage; - -import static java.lang.Integer.parseInt; -import java.util.Scanner; - -public class ThreadMenu extends Thread { - - public ThreadMenu(String name){ - super(name); - } - - public void run(){ - int i = 0; - - System.out.println("MENU : \n 1 : Voir liste des utilisateurs présents \n 2 : Initialiser communication (TCP) \n 9 : Quitter"); - int choix = 0; - while(choix != 9) { - - Scanner sc = new Scanner(System.in); - choix = sc.nextInt(); - - - switch(choix){ - case 1: System.out.println(Main.user.getListUser().toString()); - i++; - - if( i == 2) { - choix = 9 ; - } - - break; - case 2: System.out.println("A qui veux tu parler ? entre son pseudo "); - String pseudo = sc.next(); - System.out.println("pseudo entré: " + pseudo); - String[] info = Main.user.getListUser().get(pseudo).toString().split("-"); - - Main.user.startThreadTCP(info[0], parseInt(info[1],10)); - i++; - if( i == 2) { - choix = 9 ; - } - break; - - - - } - } - } -} \ No newline at end of file diff --git a/src/SourcePackage/ThreadSendTCPFinal.java b/src/SourcePackage/ThreadSendTCPFinal.java deleted file mode 100644 index 89ce68c..0000000 --- a/src/SourcePackage/ThreadSendTCPFinal.java +++ /dev/null @@ -1,71 +0,0 @@ - -package SourcePackage; - -import java.io.IOException; -import java.io.PrintWriter; -import java.net.Socket; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.Scanner; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class ThreadSendTCPFinal extends Thread { - - private Socket socket; - private boolean lancementOuPas; - private String ip; - private int port; - private Scanner sc = new Scanner(System.in); - PrintWriter writer = null; - ThreadReceiveTCPFinal threadReceive; - - public ThreadSendTCPFinal(String name, Socket socket1,boolean lancementOuPas){ - super(name); - socket = socket1; - this.lancementOuPas = lancementOuPas; - } - - @Override - public void run(){ - try { - if(lancementOuPas){ - System.out.println(" je vais envoyer pr me co>>>>>>>>>"); - socketReceiveIniationThread(socket); - } - - System.out.println("Possibilité d'envoyer des msgs "); - - writer = new PrintWriter(socket.getOutputStream()); - - while(socket.isConnected()){ - - String msg = sc.next(); - - if (msg.equals("quit")){ - this.stop(); - socket.close(); - writer.close(); - System.out.println("il est parti"); - return ; - } - - - writer.println(msg); - writer.flush(); - - - } - - } catch (IOException ex) { - Logger.getLogger(ThreadSendTCPFinal.class.getName()).log(Level.SEVERE, null, ex); - } - } - - private void socketReceiveIniationThread(Socket socket) throws UnknownHostException, IOException { - System.out.println("Avant de debuter mon thread de receive mon socket est : " + socket.isConnected()); - threadReceive = new ThreadReceiveTCPFinal(socket); - threadReceive.start(); - } - -} diff --git a/src/SourcePackage/User.java b/src/SourcePackage/User.java index 739b24b..70bea58 100644 --- a/src/SourcePackage/User.java +++ b/src/SourcePackage/User.java @@ -2,6 +2,7 @@ import GraphiquePackage.FichCom; import java.io.IOException; +import java.io.PrintWriter; import java.net.*; import java.util.ArrayList; import java.util.Date; @@ -19,7 +20,7 @@ public class User { private static boolean firstMsg = false; private HashMap listSocket; private ArrayList listFichCom; - + private PrintWriter writer = null; private HashMap listUser ; public User(String pseudo){ @@ -46,28 +47,53 @@ public void startThread(){ Thread threadReceive = new ThreadReceive("thread receive"); threadReceive.start(); - // ThreadMenu threadMenu = new ThreadMenu("thread menu"); - // threadMenu.start(); - ThreadAcceptTCP threadReceiveTCP = new ThreadAcceptTCP("receive tcp"); threadReceiveTCP.start(); } - public void startThreadTCP(String ip , int port){ - System.out.println("DEMARRAGE THREAD"); - + + public void sendMessageTCP(String msg,String ip, int port ,boolean lancementOuPas ){ + try { - listSocket.put(port, new Socket(ip,port)); + /* listSocket.put(port, new Socket(ip,port)); + Socket socket = listSocket.get(port); */ + System.out.println("port : " + port ); + Socket socket = listSocket.get(port); + + if(lancementOuPas){ + socket = new Socket(ip, port); + System.out.println(" je vais envoyer pr me co>>>>>>>>>"); + socketReceiveIniationThread(socket); + } + + writer = new PrintWriter(socket.getOutputStream()); + + /*while(socket.isConnected()){ + + if (msg.equals("quit")){ + socket.close(); + writer.close(); + System.out.println("il est parti"); + return ; + } + }*/ + + + writer.print(msg + "\n"); + writer.flush(); } catch (IOException ex) { Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); } - - - ThreadSendTCPFinal threadSendTCP = new ThreadSendTCPFinal("name",listSocket.get(port),true); - threadSendTCP.start(); - } + + + private void socketReceiveIniationThread(Socket socket) throws UnknownHostException, IOException { + System.out.println("Avant de debuter mon thread de receive mon socket est : " + socket.isConnected()); + ThreadReceiveTCPFinal threadReceive = new ThreadReceiveTCPFinal(socket); + threadReceive.start(); + } + public User getUser(){ return this; @@ -120,4 +146,10 @@ public FichCom getFichCom(int i){ return listFichCom.get(i); } + public void putListSocket(Socket socket){ + listSocket.put(socket.getPort(), socket); + } + + + } \ No newline at end of file