Compare commits
No commits in common. "1cea2246c3c8d73ddfaeb9d8a99da01a43b9d62c" and "717a2427fbe3baa3dbb53e0ff3f5bfbaae13acb0" have entirely different histories.
1cea2246c3
...
717a2427fb
9 changed files with 33 additions and 182 deletions
Binary file not shown.
|
@ -2,7 +2,6 @@ import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
@ -17,7 +16,7 @@ public class ChatApp {
|
||||||
/* Liste des utilisateurs actifs */
|
/* Liste des utilisateurs actifs */
|
||||||
private ListUtilisateurs actifUsers ;
|
private ListUtilisateurs actifUsers ;
|
||||||
private static ArrayList<Integer> ListPort = new ArrayList<Integer>();
|
private static ArrayList<Integer> ListPort = new ArrayList<Integer>();
|
||||||
private Map<Historique,String> mapHistorique ;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -129,7 +128,7 @@ public class ChatApp {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
app.modifierPseudo("Doudou");
|
app.modifierPseudo("Jean");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -160,9 +159,9 @@ class Runner implements Runnable {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (app.getMe().getPort() != 4000) {
|
||||||
UDPEchange.ecouteUDP(app);
|
UDPEchange.ecouteUDP(app);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class Historique {
|
|
||||||
private Utilisateur User1;
|
|
||||||
private Utilisateur User2;
|
|
||||||
private ArrayList<MessageHorodate> HistoriqueHorodate ;
|
|
||||||
|
|
||||||
public Historique(Utilisateur User1, Utilisateur User2) {
|
|
||||||
this.User1 = User1;
|
|
||||||
this.User2 = User2;
|
|
||||||
this.HistoriqueHorodate = new ArrayList<MessageHorodate>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addMessage(MessageHorodate mh) {
|
|
||||||
this.HistoriqueHorodate.add(mh);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Classe representant les messages envoyés en TCP lors d'une session de clavardage
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
public class MessageHorodate {
|
|
||||||
private Utilisateur destinataire ;
|
|
||||||
private Utilisateur source ;
|
|
||||||
private Date dateHorodatage ;
|
|
||||||
private String Message;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Constructeur , le message va etre horodate
|
|
||||||
* @param destinataire - Destinataire du message
|
|
||||||
* @param source - Source du message
|
|
||||||
* @param Message - Message envoye
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
public MessageHorodate(Utilisateur destinataire , Utilisateur source , String Message) {
|
|
||||||
this.destinataire = destinataire ;
|
|
||||||
this.source = source ;
|
|
||||||
this.Message = Message ;
|
|
||||||
this.dateHorodatage = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* permet de creer une representation string du message
|
|
||||||
* @return Les differents attributs de la classe sous forme de string
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
public String toString() {
|
|
||||||
String Msg = "";
|
|
||||||
Msg += ("Destinataire: " + this.destinataire + "\n") ;
|
|
||||||
Msg += ("Source: " + this.source+ "\n") ;
|
|
||||||
Msg += ("Date: " + this.dateToString() + "\n") ;
|
|
||||||
Msg += ("Message:" + this.Message + "\n" );
|
|
||||||
return Msg ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* permet de creer une representation string de la date d'horodatage
|
|
||||||
* @return La date d'horodatage du message en format yyyy/MM/dd HH:mm:ss
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
public String dateToString() {
|
|
||||||
DateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
|
||||||
return format.format(this.dateHorodatage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MessageHorodate stringToMessageHorodate(String s) {
|
|
||||||
MessageHorodate mh ;
|
|
||||||
return mh ;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,60 +0,0 @@
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
|
||||||
|
|
||||||
public class TCPEchange {
|
|
||||||
|
|
||||||
public static void envoiTCP(Utilisateur User1,Utilisateur User2, String Msg ) {
|
|
||||||
MessageHorodate mh = new MessageHorodate(User1, User2, Msg);
|
|
||||||
try {
|
|
||||||
Socket s = new Socket(User2.getIp(), User2.getPort());
|
|
||||||
PrintStream output = new PrintStream(s.getOutputStream());
|
|
||||||
output.println(mh.toString());
|
|
||||||
output.close();
|
|
||||||
s.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ecouteTCP() {
|
|
||||||
try {
|
|
||||||
ServerSocket ss = new ServerSocket(1234);
|
|
||||||
while(true) {
|
|
||||||
System.out.println("Attente Session de clavardage");
|
|
||||||
Socket link = ss.accept();
|
|
||||||
new Thread(new RunnerTCP(link)).start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class RunnerTCP implements Runnable {
|
|
||||||
final Socket link;
|
|
||||||
|
|
||||||
public RunnerTCP(Socket link) {
|
|
||||||
this.link = link;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
System.out.println("Thread started");
|
|
||||||
try {
|
|
||||||
InputStream is = link.getInputStream();
|
|
||||||
int rcv = 0;
|
|
||||||
while ((rcv = is.read()) != -1) {
|
|
||||||
System.out.println("Received: "+ rcv);
|
|
||||||
}
|
|
||||||
System.out.println("Finishing thread");
|
|
||||||
is.close();
|
|
||||||
link.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
|
@ -78,8 +78,7 @@ public class UDPEchange {
|
||||||
// Envoie en broadcast à tous les utilsateurs
|
// Envoie en broadcast à tous les utilsateurs
|
||||||
DatagramSocket socket = new DatagramSocket();
|
DatagramSocket socket = new DatagramSocket();
|
||||||
byte[]buffer = broadcastMessage.getBytes();
|
byte[]buffer = broadcastMessage.getBytes();
|
||||||
//DatagramPacket packet = new DatagramPacket( buffer, buffer.length, InetAddress.getLoopbackAddress(), port );
|
DatagramPacket packet = new DatagramPacket( buffer, buffer.length, InetAddress.getLoopbackAddress(), port );
|
||||||
DatagramPacket packet = new DatagramPacket( buffer, buffer.length, broadcastAdress, port );
|
|
||||||
socket.send(packet);
|
socket.send(packet);
|
||||||
socket.close();
|
socket.close();
|
||||||
System.out.println("***********Message envoye***********");
|
System.out.println("***********Message envoye***********");
|
||||||
|
@ -122,10 +121,10 @@ class RunnerUDP implements Runnable {
|
||||||
System.out.println("**********************************");
|
System.out.println("**********************************");
|
||||||
String Type = received.split("\n")[0];
|
String Type = received.split("\n")[0];
|
||||||
|
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//*************************************************************************************************************************
|
//*****************************************
|
||||||
//****************************************Demande de connexion****************************************
|
//Demande de connexion
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//****************************************
|
//****************************************
|
||||||
if (Type.equals("Connexion")) { // un utilisateur vient d'arriver sur le reseau
|
if (Type.equals("Connexion")) { // un utilisateur vient d'arriver sur le reseau
|
||||||
System.out.println("Reception d'une demande de connexion");
|
System.out.println("Reception d'une demande de connexion");
|
||||||
|
@ -152,11 +151,11 @@ class RunnerUDP implements Runnable {
|
||||||
|
|
||||||
( app.getActifUsers() ).afficherListeUtilisateurs();
|
( app.getActifUsers() ).afficherListeUtilisateurs();
|
||||||
}
|
}
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//*************************************************************************************************************************
|
//*****************************************
|
||||||
//****************************************Reponse d'une connexion****************************************
|
//Reponse d'une connexion
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
|
|
||||||
if (Type.equals("Reponse Connexion")) { // Un utilisateur te repond suite à ta demande de connexion
|
if (Type.equals("Reponse Connexion")) { // Un utilisateur te repond suite à ta demande de connexion
|
||||||
|
|
||||||
|
@ -171,11 +170,11 @@ class RunnerUDP implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//*************************************************************************************************************************
|
//*****************************************
|
||||||
//****************************************Demande de modification d'un pseudo****************************************
|
//Demande de modification d'un pseudo
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
|
|
||||||
if (Type.equals("Modification Pseudo")) {
|
if (Type.equals("Modification Pseudo")) {
|
||||||
if(( app.getActifUsers() ).verifierUnicite(received.split("\n")[2])) {
|
if(( app.getActifUsers() ).verifierUnicite(received.split("\n")[2])) {
|
||||||
|
@ -184,7 +183,6 @@ class RunnerUDP implements Runnable {
|
||||||
String Message = "Bon Choix Pseudo\n" + received.split("\n")[2] ;
|
String Message = "Bon Choix Pseudo\n" + received.split("\n")[2] ;
|
||||||
System.out.println(Message);
|
System.out.println(Message);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//UDPEchange.envoiUnicast(Destination.getIp(),Message, Destination.getPort());
|
//UDPEchange.envoiUnicast(Destination.getIp(),Message, Destination.getPort());
|
||||||
UDPEchange.envoiUnicast(InetAddress.getLoopbackAddress(),Message, 4000);
|
UDPEchange.envoiUnicast(InetAddress.getLoopbackAddress(),Message, 4000);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -203,10 +201,10 @@ class RunnerUDP implements Runnable {
|
||||||
}
|
}
|
||||||
( app.getActifUsers() ).afficherListeUtilisateurs();
|
( app.getActifUsers() ).afficherListeUtilisateurs();
|
||||||
}
|
}
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//*************************************************************************************************************************
|
//*****************************************
|
||||||
//****************************************Mauvais choix d'un pseudo****************************************
|
//Mauvais choix d'un pseudo
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//****************************************
|
//****************************************
|
||||||
|
|
||||||
|
|
||||||
|
@ -214,28 +212,23 @@ class RunnerUDP implements Runnable {
|
||||||
System.out.println("Ce choix de pseudo est déjà pris il te faut en choisir un autre");
|
System.out.println("Ce choix de pseudo est déjà pris il te faut en choisir un autre");
|
||||||
}
|
}
|
||||||
|
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//*************************************************************************************************************************
|
//*****************************************
|
||||||
//****************************************Bon choix d'un pseudo****************************************
|
//Bon choix d'un pseudo
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
|
|
||||||
if (Type.equals("Bon Choix Pseudo")) {
|
if (Type.equals("Bon Choix Pseudo")) {
|
||||||
|
|
||||||
( app.getActifUsers() ).supprimerList(app.getMe());
|
( app.getActifUsers() ).supprimerList(app.getMe());
|
||||||
|
|
||||||
app.getMe().setPseudo(received.split("\n")[1]);
|
app.getMe().setPseudo(received.split("\n")[1]);
|
||||||
|
|
||||||
( app.getActifUsers() ).addList(app.getMe());
|
( app.getActifUsers() ).addList(app.getMe());
|
||||||
System.out.println("Changement pseudo accepte, nouvelle liste des utilisateurs actifs:");
|
|
||||||
app.getActifUsers().afficherListeUtilisateurs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//*************************************************************************************************************************
|
//*****************************************
|
||||||
//****************************************Demande d'une deconnexion****************************************
|
//Demande d'une deconnexion
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
//************************************************************************************************************************
|
//****************************************
|
||||||
|
|
||||||
if (Type.equals("Deconnexion")) {
|
if (Type.equals("Deconnexion")) {
|
||||||
( app.getActifUsers() ).supprimerList(Utilisateur.stringToUtilisateur(received.split("\n")[1]));
|
( app.getActifUsers() ).supprimerList(Utilisateur.stringToUtilisateur(received.split("\n")[1]));
|
||||||
|
|
Loading…
Reference in a new issue