Suite connexion()
This commit is contained in:
parent
96a81001c5
commit
d696617c19
4 changed files with 41 additions and 6 deletions
BIN
Implementation/src/ChatApp.class
Normal file
BIN
Implementation/src/ChatApp.class
Normal file
Binary file not shown.
|
@ -5,6 +5,7 @@ import java.net.InetAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class ChatApp {
|
public class ChatApp {
|
||||||
|
|
||||||
|
@ -40,12 +41,40 @@ public class ChatApp {
|
||||||
DatagramPacket packet = new DatagramPacket( buffer, buffer.length, InetAddress.getLoopbackAddress(), 1234 );
|
DatagramPacket packet = new DatagramPacket( buffer, buffer.length, InetAddress.getLoopbackAddress(), 1234 );
|
||||||
socket.send(packet);
|
socket.send(packet);
|
||||||
socket.close();
|
socket.close();
|
||||||
System.out.println("Chat app -> " + broadcastMessage);
|
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) {
|
public static void main (String[] args) {
|
||||||
//Integer p = 2345 ;
|
//Integer p = 2345 ;
|
||||||
ChatApp app = new ChatApp(args[0],Integer.parseInt(args[1])) ;
|
ChatApp app = new ChatApp(args[0],Integer.parseInt(args[1])) ;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
app.connexion();
|
app.connexion();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -66,8 +95,14 @@ public class ChatApp {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
System.out.println(data);
|
String received = new String(data.getData(), 0, data.getLength());
|
||||||
}
|
System.out.println(app.me.getPseudo() + " reçoit : " + received);
|
||||||
|
app.actifUsers.add(stringToUtilisateur(received));
|
||||||
|
for(Utilisateur elem: app.actifUsers)
|
||||||
|
{
|
||||||
|
System.out.println (elem.toString());
|
||||||
|
} }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
BIN
Implementation/src/Utilisateur.class
Normal file
BIN
Implementation/src/Utilisateur.class
Normal file
Binary file not shown.
|
@ -33,9 +33,9 @@ public class Utilisateur {
|
||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
String s = "";
|
String s = "";
|
||||||
s+="pseudo " + this.pseudo + " \n";
|
s+="pseudo " + this.pseudo + " | ";
|
||||||
s+="port " + (this.port).toString() + "\n";
|
s+="port " + (this.port).toString() + " | ";
|
||||||
s+="id " + (this.ip).toString() + "\n";
|
s+="ip " + (this.ip).toString() + " | ";
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue