Phase de test sur TCP
This commit is contained in:
parent
dda0ef459e
commit
e7d01f5e35
5 changed files with 22 additions and 6 deletions
Binary file not shown.
|
|
@ -193,6 +193,7 @@ public class ChatApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(app.getMe().getPseudo().equals("Marvel")) {
|
if(app.getMe().getPseudo().equals("Marvel")) {
|
||||||
|
app.getHist("Doudou").afficher10derniers();
|
||||||
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"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -26,7 +26,7 @@ public class TCPEchange {
|
||||||
System.out.println("Socket de demarrage d'une session cree");
|
System.out.println("Socket de demarrage d'une session cree");
|
||||||
ExecutorService exec = Executors.newFixedThreadPool(1000);
|
ExecutorService exec = Executors.newFixedThreadPool(1000);
|
||||||
exec.submit(new RunnerTCPEcoute(s,app));
|
exec.submit(new RunnerTCPEcoute(s,app));
|
||||||
exec.submit(new RunnerTCPEnvoi(s,app,app.getMe()));
|
exec.submit(new RunnerTCPEnvoi(s,app,User2,false));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ public class TCPEchange {
|
||||||
System.out.println("Attente Session de clavardage");
|
System.out.println("Attente Session de clavardage");
|
||||||
Socket link = ss.accept();
|
Socket link = ss.accept();
|
||||||
exec.submit(new RunnerTCPEcoute(link,app));
|
exec.submit(new RunnerTCPEcoute(link,app));
|
||||||
exec.submit(new RunnerTCPEnvoi(link,app,app.getMe()));
|
//exec.submit(new RunnerTCPEnvoi(link,app,app.getMe()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
|
@ -81,29 +81,40 @@ class RunnerTCPEnvoi implements Runnable {
|
||||||
final BufferedReader in;
|
final BufferedReader in;
|
||||||
final PrintWriter out;
|
final PrintWriter out;
|
||||||
final Scanner sc=new Scanner(System.in);
|
final Scanner sc=new Scanner(System.in);
|
||||||
|
private boolean bonjourEnvoye = false;
|
||||||
|
|
||||||
public RunnerTCPEnvoi(Socket link,ChatApp app, Utilisateur user2 ) throws IOException {
|
public RunnerTCPEnvoi(Socket link,ChatApp app, Utilisateur user2, boolean bonjour ) throws IOException {
|
||||||
this.link = link;
|
this.link = link;
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.Destinataire = user2;
|
this.Destinataire = user2;
|
||||||
this.out = new PrintWriter(link.getOutputStream());
|
this.out = new PrintWriter(link.getOutputStream());
|
||||||
this.in = new BufferedReader (new InputStreamReader (link.getInputStream()));
|
this.in = new BufferedReader (new InputStreamReader (link.getInputStream()));
|
||||||
|
this.bonjourEnvoye = bonjour;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println("Creation d'un thread d'envoi");
|
System.out.println("Creation d'un thread d'envoi");
|
||||||
String msg;
|
String msg;
|
||||||
while(true){
|
while(true){
|
||||||
|
if(!bonjourEnvoye) {
|
||||||
|
MessageHorodate mh = new MessageHorodate(Destinataire,app.getMe(),"Bonjour",2);
|
||||||
|
bonjourEnvoye = true;
|
||||||
|
System.out.println("Envoi d'un bonjour");
|
||||||
|
out.println(mh);
|
||||||
|
out.flush();
|
||||||
|
}
|
||||||
|
else {
|
||||||
msg = sc.nextLine();
|
msg = sc.nextLine();
|
||||||
MessageHorodate mh = new MessageHorodate(Destinataire,app.getMe(),msg,1);
|
MessageHorodate mh = new MessageHorodate(Destinataire,app.getMe(),msg,1);
|
||||||
if(msg.equals("--STOP--")) {
|
if(msg.equals("--STOP--")) {
|
||||||
mh = new MessageHorodate(Destinataire,app.getMe(),msg,0);
|
mh = new MessageHorodate(Destinataire,app.getMe(),msg,0);
|
||||||
out.println(mh);
|
out.println(mh);
|
||||||
|
out.flush();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
out.println(mh);
|
out.println(mh);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
System.out.println("Fermeture du thread d'envoi");
|
System.out.println("Fermeture du thread d'envoi");
|
||||||
|
|
@ -155,8 +166,7 @@ class RunnerTCPEcoute implements Runnable {
|
||||||
h.addMessage(mh);
|
h.addMessage(mh);
|
||||||
app.majHistorique(mh.getSource().getPseudo(), h);
|
app.majHistorique(mh.getSource().getPseudo(), h);
|
||||||
}
|
}
|
||||||
else {
|
else if(mh.getType()==0) {
|
||||||
u2=mh.getSource();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,6 +176,11 @@ class RunnerTCPEcoute implements Runnable {
|
||||||
src = line+"\n";
|
src = line+"\n";
|
||||||
}
|
}
|
||||||
else if(line.split(":")[0].equals("Type")) {
|
else if(line.split(":")[0].equals("Type")) {
|
||||||
|
if(line.split(":")[1].equals("2")) {
|
||||||
|
System.out.println("Bonjour reçu!");
|
||||||
|
u2=Utilisateur.stringToUtilisateur(src.split(":")[1]);
|
||||||
|
new Thread(new RunnerTCPEnvoi(link,app,u2,true));
|
||||||
|
}
|
||||||
type = line+"\n";
|
type = line+"\n";
|
||||||
}
|
}
|
||||||
else if(line.split(":")[0].equals("Date")) {
|
else if(line.split(":")[0].equals("Date")) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue