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();
|
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"));
|
TCPEchange.demarrerSession(app, app.actifUsers.getPseudoList("Doudou"));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Je ne m'appelle pas Marvel!!!");
|
||||||
|
}
|
||||||
//app.modifierPseudo("Jean");
|
//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 class TCPEchange {
|
||||||
|
|
||||||
public static void demarrerSession(ChatApp app,Utilisateur User2 ) throws IOException {
|
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);
|
Socket s = new Socket(User2.getIp(),5000);
|
||||||
|
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,app.getMe()));
|
||||||
|
@ -52,8 +54,10 @@ public class TCPEchange {
|
||||||
public static void ecouteTCP(ChatApp app) {
|
public static void ecouteTCP(ChatApp app) {
|
||||||
ServerSocket ss = null;
|
ServerSocket ss = null;
|
||||||
ExecutorService exec = Executors.newFixedThreadPool(1000);
|
ExecutorService exec = Executors.newFixedThreadPool(1000);
|
||||||
|
System.out.println("Ecoute TCP activee");
|
||||||
try {
|
try {
|
||||||
ss = new ServerSocket(5000);
|
ss = new ServerSocket(5000);
|
||||||
|
System.out.println("Socket d'ecoute cree");
|
||||||
while(true) {
|
while(true) {
|
||||||
System.out.println("Attente Session de clavardage");
|
System.out.println("Attente Session de clavardage");
|
||||||
Socket link = ss.accept();
|
Socket link = ss.accept();
|
||||||
|
@ -87,7 +91,7 @@ class RunnerTCPEnvoi implements Runnable {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println("Thread started");
|
System.out.println("Creation d'un thread d'envoi");
|
||||||
String msg;
|
String msg;
|
||||||
while(true){
|
while(true){
|
||||||
msg = sc.nextLine();
|
msg = sc.nextLine();
|
||||||
|
@ -102,7 +106,7 @@ class RunnerTCPEnvoi implements Runnable {
|
||||||
class RunnerTCPEcoute implements Runnable {
|
class RunnerTCPEcoute implements Runnable {
|
||||||
final Socket link;
|
final Socket link;
|
||||||
private ChatApp app ;
|
private ChatApp app ;
|
||||||
|
|
||||||
public RunnerTCPEcoute(Socket link,ChatApp app ) {
|
public RunnerTCPEcoute(Socket link,ChatApp app ) {
|
||||||
this.link = link;
|
this.link = link;
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
@ -110,7 +114,7 @@ class RunnerTCPEcoute implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println("Thread started");
|
System.out.println("Creation d'un thread d'ecoute");
|
||||||
try {
|
try {
|
||||||
PrintStream output = new PrintStream(link.getOutputStream());
|
PrintStream output = new PrintStream(link.getOutputStream());
|
||||||
//InputStream is = link.getInputStream();
|
//InputStream is = link.getInputStream();
|
||||||
|
|
Loading…
Reference in a new issue