fix minor issue

This commit is contained in:
Vu Tuan Minh
2025-05-04 21:20:26 +02:00
parent aeea4e8f36
commit 06ac8a7ea5
5 changed files with 19 additions and 21 deletions

View File

@@ -35,12 +35,12 @@ public class ClientHandlerChar implements ClientHandler {
isr.close();
osw.close();
}catch (IOException e){
System.out.println(e.getMessage());
System.err.println(e.getMessage());
}finally {
try{
socket.close();
}catch (IOException e){
System.out.println(e.getMessage());
System.err.println(e.getMessage());
}
}
}

View File

@@ -7,25 +7,25 @@ import java.net.Socket;
class echoServer {
public static void main(String[] args) throws IOException{
//Attente sur le port 8080s
int portDuServer = 8080;
ServerSocket serverSocket = new ServerSocket(portDuServer);
try{
while(true){
/* Pour chaque client :
1. accepter la connexion.
2. créer un ClientHandler
3. appeler la méthode handleBytes() sur le handler
*/
boolean marche= true;
while(marche){
/* Pour chaque client :
1. accepter la connexion.
2. créer un ClientHandler
3. appeler la méthode handleBytes() sur le handler
*/
try{
Socket socket = serverSocket.accept();
ClientHandler clientHandler= new ClientHandlerChar(socket);
clientHandler.handle();
socket.close();
}catch(Exception e){
System.err.println(e.getMessage());
marche=false;
}
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}

View File

@@ -39,12 +39,12 @@ public class ClientHandlerCharMT implements ClientHandlerMT, Runnable {
isr.close();
osw.close();
}catch (IOException e){
System.out.println(e.getMessage());
System.err.println(e.getMessage());
}finally {
try{
socket.close();
}catch (IOException e){
System.out.println(e.getMessage());
System.err.println(e.getMessage());
}
}
}

View File

@@ -12,15 +12,13 @@ public class EchoServerMT {
int portEcoute = 8080;
try (ServerSocket serverSocket = new ServerSocket(portEcoute)) {
Executor service = Executors.newFixedThreadPool(4);
while(true){
while(!Thread.currentThread().isInterrupted()){
Socket socket = serverSocket.accept();
service.execute(new ClientHandlerCharMT(socket));
}
}
catch (Exception e){
e.printStackTrace();
System.err.println(e.getMessage());
}
}
}

View File

@@ -13,12 +13,12 @@ public class ServeurHTTP {
try{
ServerSocket serverSocket = new ServerSocket(portDuServer);
Executor service = Executors.newFixedThreadPool(4);
while(true){
while(!Thread.currentThread().isInterrupted()){
Socket socket = serverSocket.accept();
service.execute(new HTTPHandler(socket));
}
}catch(Exception e){
System.out.println(e.getMessage());
System.err.println(e.getMessage());
}
}
}