-
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.
avant test d'implémentation sur le projet
- Loading branch information
1 parent
8ccf889
commit 267a29f
Showing
13 changed files
with
275 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Main { | ||
|
@@ -17,4 +16,4 @@ public User getUser(){ | |
} | ||
|
||
|
||
} | ||
} |
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,52 @@ | ||
import java.io.IOException; | ||
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 Main2 { | ||
|
||
public static void main(String[] args){ | ||
int i = 0; | ||
while(true){ | ||
try { | ||
Socket client2Socket = null; | ||
ServerSocket client1Socket = new ServerSocket(45001); | ||
System.out.println("port ou jessaye d'ecouter : " + client1Socket.getLocalPort()); | ||
System.out.println(" " + client1Socket.isClosed()); | ||
Main21 threadSendTCP = null; | ||
if(!client1Socket.isClosed()) { | ||
|
||
client2Socket = client1Socket.accept(); | ||
threadSendTCP = new Main21(client2Socket); | ||
threadSendTCP.start(); | ||
} | ||
System.out.println("Connexion effective"); | ||
PrintWriter writer = new PrintWriter(client2Socket.getOutputStream()); | ||
i++; | ||
Scanner sc = new Scanner(System.in); | ||
while(!client2Socket.isClosed()) { | ||
String msg = sc.next(); | ||
|
||
writer.println(msg); | ||
writer.flush(); | ||
if(msg.equals("quit")) { | ||
writer.close(); | ||
client2Socket.close(); | ||
threadSendTCP.stop(); | ||
} | ||
|
||
} | ||
client1Socket.close(); | ||
System.out.println("closed"); | ||
|
||
|
||
} catch (IOException ex) { | ||
Logger.getLogger(ThreadReceiveTCP.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,32 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.Socket; | ||
|
||
public class Main21 extends Thread { | ||
|
||
private Socket socket; | ||
|
||
public Main21(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()) { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.PrintWriter; | ||
import java.net.Socket; | ||
import java.util.Scanner; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class MainTest { | ||
static public User user; | ||
|
||
public static void main(String[] args){ | ||
|
||
|
||
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 | ||
ThreadTesssst thread = new ThreadTesssst("ee", 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 ); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
} 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 |
---|---|---|
|
@@ -27,4 +27,4 @@ public static void sendMessage(InetAddress address, int port) throws IOException | |
|
||
} | ||
|
||
} | ||
} |
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,52 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.PrintWriter; | ||
import java.net.Socket; | ||
import java.util.Scanner; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class ThreadISendTCP { | ||
static public User user; | ||
|
||
public static void main(String[] args){ | ||
|
||
|
||
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 ); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
} 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
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 |
---|---|---|
|
@@ -61,4 +61,4 @@ public synchronized static void ajoutUserListe(String pseudo, String ip){ | |
} | ||
|
||
|
||
} | ||
} |
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 |
---|---|---|
|
@@ -34,4 +34,4 @@ public static void sendMessageBroadcast() throws IOException { | |
User.getSocketEnvoi().send(packet); | ||
} | ||
|
||
} | ||
} |
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
Oops, something went wrong.