Skip to content

Commit

Permalink
eddeded
Browse files Browse the repository at this point in the history
  • Loading branch information
ElyesKhama committed Dec 22, 2017
1 parent 1ecde72 commit e0e22ca
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/GraphiquePackage/FichAccueil.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ private void PseudoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

try {

Main.launchUser("");
Main.launchUser("first");

String a = Pseudo.getText();
System.out.println("Checking pseudo ...");

System.out.println("Checking pseudo ...");
sleep(3000);

if(Main.user.getListUser().containsKey(a)){
Expand All @@ -111,6 +110,7 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS

else{
Main.user.setPseudo(a);

menu = new FichMenu(this, false);
this.setVisible(false);
menu.setVisible(true);
Expand Down
2 changes: 1 addition & 1 deletion src/SourcePackage/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void main(String[] args){

public static void launchUser(String pseudo){
user = new User(pseudo);
user.startThread();
user.startThread(pseudo);
}


Expand Down
14 changes: 7 additions & 7 deletions src/SourcePackage/ThreadReceive.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ else if(recvStr.contains("quito")){
System.out.print("etat du socket : "+ User.getSocketEcoute());
Main.user.removeSocketList(recvPacket.getPort());
}
else if(recvStr.equals("first")){
System.out.println("lancement de l'appli");
}

else {
if( !Main.user.belongList(recvStr)){
if(recvStr.equals("")){

}
else{

InetAddress addr = recvPacket.getAddress();

InetAddress addr = recvPacket.getAddress();
int port = recvPacket.getPort();
sendMessage(addr, port);
System.out.println("je rentre");
ajoutUserListe(recvStr,addr.toString().substring(1)+"-"+port);
}

}
}
}
Expand Down
23 changes: 15 additions & 8 deletions src/SourcePackage/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ public User(String pseudo){
}
this.pseudo = pseudo;

System.out.println("J'ai crée un utilisateur ; son pseudo est : " + pseudo );
}

public void startThread(){
sendMessageUDP(null,0);
public void startThread(String s){
if (s.equals("first")){
sendMessageUDP(s,0);
}
else{
sendMessageUDP(null,0);

}

Thread threadReceive = new ThreadReceive("thread receive");
threadReceive.start();
Expand All @@ -58,16 +63,17 @@ public void startThread(int i){

public void sendMessageUDP(String message,int port){
String data = "" ;

if(message != null ){
if(message.equals("first"))
data = message;
else if(message != null){
data = message+"-"+pseudo;
listSocket.remove(port);
}
else {
data = Main.user.getPseudo();
data = Main.user.getPseudo();
}

System.out.println(Main.user);
System.out.println(data + " gr");
try {
User.getSocketEnvoi().setBroadcast(true);
InetAddress address = InetAddress.getByName("255.255.255.255"); //mettre l'adresse de broadcast directement
Expand Down Expand Up @@ -134,7 +140,8 @@ public String getPseudo(){
return this.pseudo;
}

public void setPseudo(String pseudo){
public void setPseudo(String pseudo){ //mon pseudo a changé donc je vais renvoyer en broadcast mon pseudo
sendMessageUDP(pseudo,0);
this.pseudo = pseudo;
}
@Override
Expand Down

0 comments on commit e0e22ca

Please sign in to comment.