-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d96636
commit 11df437
Showing
10 changed files
with
224 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import java.io.IOException; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
|
||
public class ThreadAcceptTCP extends Thread{ | ||
|
||
private ThreadReceiveTCPFinal threadReceiveTCP = null; | ||
private ThreadSendTCPFinal threadSendTCP = null; | ||
|
||
|
||
public ThreadAcceptTCP(String name) { | ||
super(name); | ||
} | ||
|
||
public void run() { | ||
Socket client2Socket = null; | ||
ServerSocket client1Socket; | ||
try { | ||
client1Socket = new ServerSocket(Main.user.getPort()); | ||
System.out.println("port ou jessaye d'ecouter : " + client1Socket.getLocalPort()); | ||
System.out.println(" " + client1Socket.isClosed()); | ||
if(!client1Socket.isClosed()) { | ||
|
||
client2Socket = client1Socket.accept(); | ||
threadReceiveTCP = new ThreadReceiveTCPFinal(client2Socket); | ||
threadReceiveTCP.start(); | ||
threadSendTCP = new ThreadSendTCPFinal("Send",client2Socket.getInetAddress().toString(),client2Socket.getPort(),client2Socket,false); | ||
threadSendTCP.start(); | ||
} | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,43 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.PrintWriter; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
import java.util.Scanner; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class ThreadReceiveTCP extends Thread { | ||
static public User user; | ||
|
||
public ThreadReceiveTCP(String name){ | ||
} | ||
public void run(){ | ||
Socket socket; | ||
try { | ||
socket = new Socket("192.168.2.5",45001); | ||
System.out.println("port ou jessaye d'envoyer "+ 45001 ); | ||
if(socket.isConnected()){ //Envoie des msgs | ||
Main21 thread = new Main21(socket); | ||
thread.start(); | ||
System.out.println("démarrage du thread d'envoie des msgs"); | ||
} | ||
|
||
InputStreamReader stream = new InputStreamReader(socket.getInputStream()); | ||
BufferedReader reader = new BufferedReader(stream); | ||
//System.out.println("je vais lui rep "); | ||
// System.out.println("je lui ai rep "); | ||
// testMsg(socket); | ||
|
||
|
||
|
||
while(socket.isConnected()){ // Boucle de réception des msgs | ||
String a = reader.readLine(); | ||
if (a != null ){ | ||
System.out.println("le client m'a envoyé : " + a ); | ||
} | ||
ServerSocket client1Socket = null; | ||
|
||
public ThreadReceiveTCP(String name){ | ||
super(name); | ||
|
||
} | ||
|
||
public void run(){ | ||
|
||
|
||
try { | ||
System.out.println("Lancement de l'ecoute tcp"); | ||
client1Socket = new ServerSocket(Main.user.getPort()); | ||
} catch (IOException ex) { | ||
Logger.getLogger(ThreadReceiveTCP.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
|
||
while(true){ | ||
try { | ||
System.out.println("port ou jessaye d'ecouter : " + client1Socket.getLocalPort()); | ||
Socket client2Socket = client1Socket.accept(); | ||
System.out.println("Connexion effective"); | ||
PrintWriter writer = new PrintWriter(client2Socket.getOutputStream()); | ||
writer.println("Coucou "); | ||
writer.close(); | ||
} catch (IOException ex) { | ||
Logger.getLogger(ThreadReceiveTCP.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} catch (IOException ex) { | ||
Logger.getLogger(ThreadSendTCP.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.Socket; | ||
|
||
public class ThreadReceiveTCPFinal extends Thread { | ||
|
||
private Socket socket; | ||
|
||
public ThreadReceiveTCPFinal(Socket socket) { | ||
this.socket = socket; | ||
} | ||
|
||
public void run() { | ||
InputStreamReader stream; | ||
try { | ||
stream = new InputStreamReader(socket.getInputStream()); | ||
BufferedReader reader = new BufferedReader(stream); | ||
System.out.println("Je vais lire1"); | ||
while(socket.isConnected()) { | ||
System.out.println("Je lis "); | ||
|
||
String a = reader.readLine(); | ||
if(a != null) | ||
System.out.println(a); | ||
} | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.net.Socket; | ||
import java.util.Scanner; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class ThreadSendTCPFinal extends Thread { | ||
|
||
private Socket socket; | ||
private boolean lancementOuPas; | ||
private String ip; | ||
private int port; | ||
|
||
public ThreadSendTCPFinal(String name,String ip, int port, Socket socket1,boolean lancementOuPas){ | ||
super(name); | ||
socket = socket1; | ||
this.lancementOuPas = lancementOuPas; | ||
this.ip = ip; | ||
this.port = port; | ||
} | ||
|
||
@Override | ||
public void run(){ | ||
try { | ||
if(lancementOuPas) { | ||
System.out.println("je passe mauvais delir "); | ||
socket = new Socket(ip,port); | ||
ThreadReceiveTCPFinal threadReceive = new ThreadReceiveTCPFinal( socket); | ||
threadReceive.start(); | ||
} | ||
PrintWriter writer = null; | ||
Scanner sc = new Scanner(System.in); | ||
System.out.println("Possibilité d'envoyer des msgs "); | ||
writer = new PrintWriter(socket.getOutputStream()); | ||
while(socket.isConnected()){ | ||
String msg = sc.next(); | ||
|
||
if (msg.equals("quit")){ | ||
this.stop(); | ||
socket.close(); | ||
writer.close(); | ||
System.out.println("il est parti"); | ||
return ; | ||
} | ||
|
||
|
||
writer.println(msg); | ||
writer.flush(); | ||
} | ||
|
||
} catch (IOException ex) { | ||
Logger.getLogger(ThreadSendTCPFinal.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.