Suite connexion() 2

This commit is contained in:
Auriane Lartigue 2020-11-26 10:12:58 +01:00
parent d696617c19
commit 00cedc86d8
4 changed files with 20 additions and 28 deletions

Binary file not shown.

View file

@ -44,33 +44,7 @@ public class ChatApp {
System.out.println(this.me.getPseudo() + " envoie : " + broadcastMessage);
}
public static Utilisateur stringToUtilisateur(String s){
String lines[] = s.split("|");
String name = "";
Integer port = 0;
String ip = "" ;
for (String line : lines ){
String mots[] = line.split(" ");
if (mots[0]=="pseudo"){
name=mots[1];
}
if(mots[0]=="port")
{
port=Integer.parseInt(mots[1]);
}
if(mots[0]=="ip")
{
ip=mots[1];
}
}
Utilisateur user = null;
try {
user = new Utilisateur(name,port,InetAddress.getByName(ip));
} catch (UnknownHostException e) {
e.printStackTrace();
}
return user;
}
public static void main (String[] args) {
//Integer p = 2345 ;
ChatApp app = new ChatApp(args[0],Integer.parseInt(args[1])) ;
@ -97,7 +71,7 @@ public class ChatApp {
}
String received = new String(data.getData(), 0, data.getLength());
System.out.println(app.me.getPseudo() + " reçoit : " + received);
app.actifUsers.add(stringToUtilisateur(received));
app.actifUsers.add(Utilisateur.stringToUtilisateur(received));
for(Utilisateur elem: app.actifUsers)
{
System.out.println (elem.toString());

Binary file not shown.

View file

@ -1,4 +1,5 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
public class Utilisateur {
@ -39,4 +40,21 @@ public class Utilisateur {
return s;
}
public static Utilisateur stringToUtilisateur(String s){
String name = "";
Integer port = 0;
String ip = "" ;
String mots[] = s.split(" ");
name=mots[1];
port=Integer.parseInt(mots[4]);
ip=mots[7];
Utilisateur user = null;
try {
user = new Utilisateur(name,port,InetAddress.getByName(ip.split("/")[0]));
} catch (UnknownHostException e) {
e.printStackTrace();
}
return user;
}
}