diff --git a/Projet_POO/src/clavardage/gestionnaireClavardage.java b/Projet_POO/src/clavardage/gestionnaireClavardage.java index 7c11cc0..c3d7f4a 100644 --- a/Projet_POO/src/clavardage/gestionnaireClavardage.java +++ b/Projet_POO/src/clavardage/gestionnaireClavardage.java @@ -2,5 +2,4 @@ package clavardage; public class gestionnaireClavardage { sessions = - } diff --git a/Projet_POO/src/reseau/TCPServer.java b/Projet_POO/src/reseau/TCPServer.java index 0bdd9a4..93d4b89 100644 --- a/Projet_POO/src/reseau/TCPServer.java +++ b/Projet_POO/src/reseau/TCPServer.java @@ -1,5 +1,7 @@ package reseau; import java.net.*; +import java.util.ArrayList; +import java.util.List; import java.io.*; @@ -8,6 +10,7 @@ public class TCPServer { ServerSocket socket; private String host; private int port; + private List clients = new ArrayList(); private InetAddress address; public TCPServer (String host, int backlog, int port) { @@ -30,37 +33,26 @@ public class TCPServer { } - public Socket accept() throws IOException{ - return this.socket.accept(); + public void accept() { + Socket ssocket = null; + try { + ssocket = this.socket.accept(); + } + catch (IOException e) { + System.out.print("Erreur lors de la connexion avec un client"); + } + new TCPServerThread(ssocket); + this.clients.add(ssocket); + } public static void main(String[] args) { + TCPServer server = new TCPServer("localhost", 5, 1999); - Socket link = null; - BufferedReader input = null; - PrintWriter output = null; - try { - link = server.accept(); - input = new BufferedReader(new InputStreamReader(link.getInputStream())); - output = new PrintWriter(link.getOutputStream(),true); - } - catch (IOException e) { - System.out.print("Error while connecting to client"); - } - try { - String message = input.readLine(); - output.print(message); - output.flush(); - } - catch (IOException e) { - System.out.print("Error while communicating with client"); - } - try { - link.close(); - } - catch (IOException e) { - System.out.print("Error while closing connection"); + + while(true) { + server.accept(); } } diff --git a/Projet_POO/src/reseau/TCPServerThread.java b/Projet_POO/src/reseau/TCPServerThread.java index abece46..afac6b2 100644 --- a/Projet_POO/src/reseau/TCPServerThread.java +++ b/Projet_POO/src/reseau/TCPServerThread.java @@ -7,7 +7,7 @@ import java.io.PrintWriter; import java.net.Socket; import java.net.UnknownHostException; -public class TCPServerThread extends tcpClient implements Runnable{ +public class TCPServerThread extends TCPClient implements Runnable{ Thread thread; diff --git a/Projet_POO/src/reseau/TCPServerWithThreads.java b/Projet_POO/src/reseau/TCPServerWithThreads.java deleted file mode 100644 index f0eb907..0000000 --- a/Projet_POO/src/reseau/TCPServerWithThreads.java +++ /dev/null @@ -1,32 +0,0 @@ -package reseau; -import java.io.IOException; -import java.net.*; - -public class TCPServerWithThreads extends TCPServer{ - private TCPServerThread[] clientThreads; - - public TCPServerWithThreads (String host, int backlog, int port) { - super(host, backlog, port); - } - - public Socket accept() { - Socket ssocket = null; - try { - ssocket = this.socket.accept(); - } - catch (IOException e) { - - } - new TCPServerThread(ssocket); - return ssocket; - } - - public static void main(String[] args) { - - TCPServerWithThreads server = new TCPServerWithThreads("localhost", 5, 19999); - - while(true) { - server.accept(); - } - } -} diff --git a/Projet_POO/src/reseau/broadcast.java b/Projet_POO/src/reseau/broadcast.java deleted file mode 100644 index e59a3f9..0000000 --- a/Projet_POO/src/reseau/broadcast.java +++ /dev/null @@ -1,11 +0,0 @@ -package reseau; - -public class broadcast { - - public static void main(String[] args) { - // TODO Auto-generated method stub - System.out.print("Quelquechose"); - System.out.print("Quelquechose 2 le retour"); - } - -} diff --git a/Projet_POO/src/reseau/tcpClient.java b/Projet_POO/src/reseau/tcpClient.java deleted file mode 100644 index 3021ba8..0000000 --- a/Projet_POO/src/reseau/tcpClient.java +++ /dev/null @@ -1,91 +0,0 @@ -package reseau; -import java.net.*; -import java.io.*; - -public class tcpClient { - String host = null; - int port = 0; - Socket socket = null; - BufferedReader input = null; - PrintWriter output = null; - - public tcpClient() { - this.host = null; - this.port = 0; - this.socket = null; - this.input = null; - this.output = null; - } - - public tcpClient(String host, int port) { - this.host = host; - this.port = port; - try { - this.socket = new Socket(host, port); - } - catch (UnknownHostException e) { - System.out.print("Could not find host"); - } - catch (IOException e) { - System.out.print("Could not create socket"); - } - try { - this.input = new BufferedReader(new InputStreamReader(socket.getInputStream())); - } - catch (IOException e) { - System.out.print("Error while reading input stream"); - } - try { - this.output = new PrintWriter(socket.getOutputStream(),true); - } - catch (IOException e) { - System.out.print("Error while reading output stream"); - } - - } - - public void send(String message) { - this.output.print(message); - this.output.flush(); - } - - public String receive() { - String message = null; - try { - message = input.readLine(); - } - catch (IOException e) { - System.out.print("Error while reading buffer"); - } - return message; - } - - public void stop() { - try { - this.socket.close(); - } - catch (IOException e) { - System.out.print("Error while closing connection"); - } - - - } - - public void changePort(int port) throws IOException { - this.stop(); - this.port = port; - try { - this.socket = new Socket(host, port); - } - catch (UnknownHostException e) { - System.out.print("Could not find host"); - } - } - - public static void main(String[] args) { - tcpClient client = new tcpClient("localhost", 19999); - client.send("Bonjour\n"); - System.out.print(client.receive()); - client.stop(); - } -}