1
0
Ответвление 0

Gestion UDP terminee et gestion TCP en cours

Этот коммит содержится в:
Nabil Moukhlis 2020-12-07 11:48:24 +01:00
родитель 5a20c9fd06
коммит ba901972cd
7 изменённых файлов: 33 добавлений и 9 удалений

Двоичные данные
Implementation/src/ChatApp.class

Двоичный файл не отображается.

Просмотреть файл

@ -41,11 +41,7 @@ public class ChatApp {
this.actifUsers = new ListUtilisateurs() ; this.actifUsers = new ListUtilisateurs() ;
// Recuperer adresse IP de l'utilisateur // Recuperer adresse IP de l'utilisateur
InetAddress ip = null ; InetAddress ip = null ;
try { ip = UDPEchange.getCurrentIp();
ip = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
this.me = new Utilisateur(pseudo,port,ip); this.me = new Utilisateur(pseudo,port,ip);
this.actifUsers.addList(getMe()); this.actifUsers.addList(getMe());
this.mapHistorique = new HashMap<String,Historique>() ; this.mapHistorique = new HashMap<String,Historique>() ;
@ -177,6 +173,10 @@ public class ChatApp {
public static void main (String[] args) throws IOException { public static void main (String[] args) throws IOException {
ChatApp app = new ChatApp(args[0],Integer.parseInt(args[1])) ; ChatApp app = new ChatApp(args[0],Integer.parseInt(args[1])) ;
ExecutorService execUDP = Executors.newFixedThreadPool(1000); ExecutorService execUDP = Executors.newFixedThreadPool(1000);
execUDP.submit(new RunnerEcouteUDP(app)); execUDP.submit(new RunnerEcouteUDP(app));
try { try {
@ -196,10 +196,8 @@ public class ChatApp {
System.out.println("Tentative de connexion avec Doudou"); System.out.println("Tentative de connexion avec Doudou");
TCPEchange.demarrerSession(app, app.actifUsers.getPseudoList("Doudou")); TCPEchange.demarrerSession(app, app.actifUsers.getPseudoList("Doudou"));
} }
else {
System.out.println("Je ne m'appelle pas Marvel!!!");
}
//app.modifierPseudo("Jean");
} }

Двоичные данные
Implementation/src/RunnerEcouteTCP.class

Двоичный файл не отображается.

Двоичные данные
Implementation/src/RunnerEcouteUDP.class

Двоичный файл не отображается.

Двоичные данные
Implementation/src/RunnerUDP.class

Двоичный файл не отображается.

Двоичные данные
Implementation/src/UDPEchange.class

Двоичный файл не отображается.

Просмотреть файл

@ -1,9 +1,11 @@
import java.io.IOException; import java.io.IOException;
import java.net.DatagramPacket; import java.net.DatagramPacket;
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.net.Inet4Address;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
@ -56,6 +58,30 @@ public class UDPEchange {
PseudoValide = value ; PseudoValide = value ;
} }
public static InetAddress getCurrentIp() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) networkInterfaces
.nextElement();
Enumeration<InetAddress> nias = ni.getInetAddresses();
while(nias.hasMoreElements()) {
InetAddress ia= (InetAddress) nias.nextElement();
if (!ia.isLinkLocalAddress()
&& !ia.isLoopbackAddress()
&& ia instanceof Inet4Address) {
return ia;
}
}
}
} catch (SocketException e) {
System.out.println("unable to get current IP " + e.getMessage());
}
return null;
}
/** /**
* <p> * <p>
* Méthode permettant d'envoyer un message à tout les utilisateurs * Méthode permettant d'envoyer un message à tout les utilisateurs