Skip to content

Commit

Permalink
test fermeture connexion TCP
Browse files Browse the repository at this point in the history
  • Loading branch information
ElyesKhama committed Dec 22, 2017
1 parent 9170e16 commit 9bc3923
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/GraphiquePackage/FichAccueil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,12 @@ public class FichAccueil extends javax.swing.JFrame {

public FichAccueil() {

exitSystem();

initComponents();

}

public void exitSystem(){
this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
Main.user.sendMessageUDP("quita");
System.exit(0);
}
});
}


/**
* 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
Expand Down
15 changes: 15 additions & 0 deletions src/GraphiquePackage/FichCom.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ public FichCom(java.awt.Dialog parent, boolean modal, int port ) {
super(parent, modal);
initComponents();
portDest = port ;

exitSystem();

}


public void exitSystem(){
this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
Main.user.sendMessageUDP("quito");
System.out.println("jai send le msg" );
System.exit(0);
}
});
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/GraphiquePackage/FichMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,20 @@ public FichMenu(FichAccueil parent, boolean modal) {
ThreadPrintListUser threadPrint = new ThreadPrintListUser("thread print");
threadPrint.start();

exitSystem();
}

public void exitSystem(){
this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
Main.user.sendMessageUDP("quita");
System.out.println("jai send le msg" );
System.exit(0);
}
});
}


public static void setListUser(String liste){
listUser.setText(liste);
Expand Down
4 changes: 4 additions & 0 deletions src/SourcePackage/ThreadReceive.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static void receiveMessage() throws IOException { //UDP : boucle qui re
Main.user.removeUserList(info[1]);//mettre a jour sa liste : l'enlever
}

else if(recvStr.contains("quito")){
Main.user.removeSocketList(recvPacket.getPort());
}

else {
if( !Main.user.belongList(recvStr)){
InetAddress addr = recvPacket.getAddress();
Expand Down
15 changes: 15 additions & 0 deletions src/SourcePackage/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,24 @@ public void setListUser(String pseudo, String ipPort){
}

public void removeUserList(String pseudo1){
System.out.println("J'ai remove !!! ");
this.listUser.remove(pseudo1);
}

public void removeSocketList(int port){
System.out.println("J'ai fermé la co !!! ");
System.out.println("Etat du socket avant : "+ listSocket.get(port).isConnected());

try {
listSocket.get(port).close();
} catch (IOException ex) {
Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Etat du socket apres : "+ listSocket.get(port).isConnected());

this.listSocket.remove(port);
}

public boolean belongList(String pseudo){
if (listUser.containsKey(pseudo)){
return true;
Expand Down

0 comments on commit 9bc3923

Please sign in to comment.