Skip to content

Commit

Permalink
pour chemszer
Browse files Browse the repository at this point in the history
  • Loading branch information
ElyesKhama committed Dec 14, 2017
1 parent 97aedc9 commit 4023549
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.
4 changes: 1 addition & 3 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
public class Main {
public static void main(String[] args){
User user1 = new User("elyes");


User user1 = new User("elyes2");
}
}
23 changes: 7 additions & 16 deletions src/SendMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,22 @@

public class SendMessage {

private static DatagramSocket socket_envoi;
private static DatagramSocket socket_ecoute;

public static DatagramSocket getSocketEcoute() {
return socket_ecoute;
}

public static DatagramSocket getSocketEnvoi(){
return socket_envoi;
}

public static void sendMessage(InetAddress address, int port, User user) throws IOException {

try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}

//String data = user.getPseudo();
String data = user.getPseudo();
DatagramPacket packet = new DatagramPacket(data.getBytes(),
data.getBytes().length, address, port);
System.out.println("J'ai bien envoyé mon paquet à " + address+ "sur le port : " + port + "\n temps : "+ System.currentTimeMillis());

socket_envoi.send(packet);
data.getBytes().length, address, 45047);
System.out.println("J'ai renvoyé mon paquet apres l'ecoute sur le port : " + 45047);


User.getSocketEcoute().send(packet);


}
Expand Down
2 changes: 2 additions & 0 deletions src/ThreadReceive.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public static void receiveMessage() throws IOException {


ajoutUserListe(recvStr, addr.toString());
SendMessage.sendMessage(addr, port, user);


}

Expand Down
17 changes: 7 additions & 10 deletions src/ThreadSend.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ThreadSend extends Thread{

Expand All @@ -11,18 +13,13 @@ public ThreadSend(String name, User user){
}

public void run(){

try {
for(int i=0;i<10;i++) {
sendMessageBroadcast(user);
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
sendMessageBroadcast(user);
} catch (IOException ex) {
Logger.getLogger(ThreadSend.class.getName()).log(Level.SEVERE, null, ex);
}

}

public static void sendMessageBroadcast(User user) throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion src/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public User(String pseudo){

System.out.println("J'ai crée un utilisateur ; son pseudo est : " + pseudo );
Thread threadSend = new ThreadSend("thread send", this);
// threadSend.start();
threadSend.start();

Thread threadReceive = new ThreadReceive("thread receive", this);
threadReceive.start();
Expand Down

0 comments on commit 4023549

Please sign in to comment.