Merge branch 'master' of https://gitlab2.istic.univ-rennes1.fr/trochas/tp1.http
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package fr.istic.pr.echo;
|
||||
|
||||
public interface ClientHandler {
|
||||
public interface ClientHandler {
|
||||
/** La méthode handle traite le client **/
|
||||
public void handle();
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
public class ClientHandlerBytes implements ClientHandler {
|
||||
public class ClientHandlerBytes implements ClientHandler, Runnable {
|
||||
|
||||
private Socket socket;
|
||||
|
||||
@@ -35,4 +35,9 @@ public class ClientHandlerBytes implements ClientHandler {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,53 @@
|
||||
package fr.istic.pr.echo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
//import static jdk.internal.org.jline.utils.Colors.s;
|
||||
|
||||
public class EchoServer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
//Attente sur le port 8080
|
||||
private static ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
private ServerSocket serverSocket;
|
||||
private static EchoServer echoServer;
|
||||
|
||||
/* Pour chaque client :
|
||||
1. accepter la connexion.
|
||||
2. créer un ClientHandler
|
||||
3. appeler la méthode handleBytes() sur le handler
|
||||
*/
|
||||
|
||||
private void run_Serveur() throws IOException {
|
||||
//Attente sur le port 8080s
|
||||
//int num_de_client=1;
|
||||
int portDuServeur= 8080;
|
||||
ServerSocket serverSocket = new ServerSocket(portDuServeur);
|
||||
try{
|
||||
while(true){
|
||||
System.out.println("Coucou");
|
||||
Socket socket = serverSocket.accept();
|
||||
//ClientHandler clientHandler= new ClientHandler(serverSocket,num_de_client);
|
||||
executorService.submit(new ClientHandlerBytes(socket));
|
||||
/* Pour chaque client :
|
||||
1. accepter la connexion.
|
||||
2. créer un ClientHandler
|
||||
3. appeler la méthode handleBytes() sur le handler
|
||||
*/
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void arret_Serveur(){
|
||||
executorService.shutdownNow();
|
||||
try{
|
||||
serverSocket.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) throws IOException {
|
||||
echoServer= new EchoServer();
|
||||
echoServer.run_Serveur();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user