Implementation TCP
This commit is contained in:
parent
4c36d6fe24
commit
8f1c3e6a9b
8 changed files with 12 additions and 4 deletions
Binary file not shown.
|
@ -191,9 +191,13 @@ public class ChatApp {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(app.getMe().getPseudo()=="Marvel") {
|
||||
if(app.getMe().getPseudo().equals("Marvel")) {
|
||||
System.out.println("Tentative de connexion avec Doudou");
|
||||
TCPEchange.demarrerSession(app, app.actifUsers.getPseudoList("Doudou"));
|
||||
}
|
||||
else {
|
||||
System.out.println("Je ne m'appelle pas Marvel!!!");
|
||||
}
|
||||
//app.modifierPseudo("Jean");
|
||||
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -20,7 +20,9 @@ import java.io.InputStreamReader;
|
|||
public class TCPEchange {
|
||||
|
||||
public static void demarrerSession(ChatApp app,Utilisateur User2 ) throws IOException {
|
||||
System.out.println("Demmarrage d'une session de clavardage");
|
||||
Socket s = new Socket(User2.getIp(),5000);
|
||||
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()));
|
||||
|
@ -52,8 +54,10 @@ public class TCPEchange {
|
|||
public static void ecouteTCP(ChatApp app) {
|
||||
ServerSocket ss = null;
|
||||
ExecutorService exec = Executors.newFixedThreadPool(1000);
|
||||
System.out.println("Ecoute TCP activee");
|
||||
try {
|
||||
ss = new ServerSocket(5000);
|
||||
System.out.println("Socket d'ecoute cree");
|
||||
while(true) {
|
||||
System.out.println("Attente Session de clavardage");
|
||||
Socket link = ss.accept();
|
||||
|
@ -87,7 +91,7 @@ class RunnerTCPEnvoi implements Runnable {
|
|||
}
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Thread started");
|
||||
System.out.println("Creation d'un thread d'envoi");
|
||||
String msg;
|
||||
while(true){
|
||||
msg = sc.nextLine();
|
||||
|
@ -110,7 +114,7 @@ class RunnerTCPEcoute implements Runnable {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Thread started");
|
||||
System.out.println("Creation d'un thread d'ecoute");
|
||||
try {
|
||||
PrintStream output = new PrintStream(link.getOutputStream());
|
||||
//InputStream is = link.getInputStream();
|
||||
|
|
Loading…
Reference in a new issue