diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Matiski/Matiski2HandlerThread.java b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Matiski/Matiski2HandlerThread.java index 2de45ad079c4fc7017d7d4bd25cba1c17ecbe998..dd70c8524af605297e581e18fd8ba936518c8129 100644 --- a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Matiski/Matiski2HandlerThread.java +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Matiski/Matiski2HandlerThread.java @@ -56,7 +56,7 @@ public class Matiski2HandlerThread extends Thread * the client won't see a server connection response for ten seconds (default). */ // @overriding run() method in Java Thread class is deliberate - @Override +@Override public void run() { try @@ -78,7 +78,8 @@ public void run() String clientPassword = br.readLine(); // Read the password sent by the client - if (correctPassword.equals(clientPassword)) { + boolean isPasswordCorrect = correctPassword.equals(clientPassword); + if (isPasswordCorrect) { ps.println("Password accepted. Processing your request..."); ps.flush(); @@ -95,6 +96,14 @@ public void run() ps.flush(); } + // Inform the client that the connection will be closed + if (isPasswordCorrect) { + ps.println("Your request has been processed. The connection will now be closed."); + } else { + ps.println("Due to incorrect password, the connection will be closed."); + } + ps.flush(); + socket.close(); // Close the socket after handling the connection System.out.println(Matiski2HandlerThread.class.getName() + " finished handling a thread, now exit."); } @@ -107,4 +116,5 @@ public void run() System.out.println("*** Be sure to stop any other running instances of programs using this port!"); } } + }