Gestion UDP terminee et gestion TCP en cours
This commit is contained in:
parent
5a20c9fd06
commit
ba901972cd
7 changed files with 33 additions and 9 deletions
Binary file not shown.
|
@ -41,11 +41,7 @@ public class ChatApp {
|
|||
this.actifUsers = new ListUtilisateurs() ;
|
||||
// Recuperer adresse IP de l'utilisateur
|
||||
InetAddress ip = null ;
|
||||
try {
|
||||
ip = InetAddress.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ip = UDPEchange.getCurrentIp();
|
||||
this.me = new Utilisateur(pseudo,port,ip);
|
||||
this.actifUsers.addList(getMe());
|
||||
this.mapHistorique = new HashMap<String,Historique>() ;
|
||||
|
@ -177,6 +173,10 @@ public class ChatApp {
|
|||
|
||||
public static void main (String[] args) throws IOException {
|
||||
ChatApp app = new ChatApp(args[0],Integer.parseInt(args[1])) ;
|
||||
|
||||
|
||||
|
||||
|
||||
ExecutorService execUDP = Executors.newFixedThreadPool(1000);
|
||||
execUDP.submit(new RunnerEcouteUDP(app));
|
||||
try {
|
||||
|
@ -196,10 +196,8 @@ public class ChatApp {
|
|||
System.out.println("Tentative de connexion avec Doudou");
|
||||
TCPEchange.demarrerSession(app, app.actifUsers.getPseudoList("Doudou"));
|
||||
}
|
||||
else {
|
||||
System.out.println("Je ne m'appelle pas Marvel!!!");
|
||||
}
|
||||
//app.modifierPseudo("Jean");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,9 +1,11 @@
|
|||
import java.io.IOException;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.Inet4Address;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
@ -56,6 +58,30 @@ public class UDPEchange {
|
|||
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>
|
||||
* Méthode permettant d'envoyer un message à tout les utilisateurs
|
||||
|
|
Loading…
Reference in a new issue