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")) {
|
||||
app.getHist("Doudou").afficher10derniers();
|
||||
System.out.println("Tentative de connexion avec 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");
|
||||
ExecutorService exec = Executors.newFixedThreadPool(1000);
|
||||
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");
|
||||
Socket link = ss.accept();
|
||||
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) {
|
||||
|
@ -81,29 +81,40 @@ class RunnerTCPEnvoi implements Runnable {
|
|||
final BufferedReader in;
|
||||
final PrintWriter out;
|
||||
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.app = app;
|
||||
this.Destinataire = user2;
|
||||
this.out = new PrintWriter(link.getOutputStream());
|
||||
this.in = new BufferedReader (new InputStreamReader (link.getInputStream()));
|
||||
this.bonjourEnvoye = bonjour;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Creation d'un thread d'envoi");
|
||||
String msg;
|
||||
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();
|
||||
MessageHorodate mh = new MessageHorodate(Destinataire,app.getMe(),msg,1);
|
||||
if(msg.equals("--STOP--")) {
|
||||
mh = new MessageHorodate(Destinataire,app.getMe(),msg,0);
|
||||
out.println(mh);
|
||||
out.flush();
|
||||
break;
|
||||
}
|
||||
out.println(mh);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
try {
|
||||
System.out.println("Fermeture du thread d'envoi");
|
||||
|
@ -155,8 +166,7 @@ class RunnerTCPEcoute implements Runnable {
|
|||
h.addMessage(mh);
|
||||
app.majHistorique(mh.getSource().getPseudo(), h);
|
||||
}
|
||||
else {
|
||||
u2=mh.getSource();
|
||||
else if(mh.getType()==0) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -166,6 +176,11 @@ class RunnerTCPEcoute implements Runnable {
|
|||
src = line+"\n";
|
||||
}
|
||||
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";
|
||||
}
|
||||
else if(line.split(":")[0].equals("Date")) {
|
||||
|
|
Loading…
Reference in a new issue