diff --git a/build/classes/java/main/iterative/Client.class b/build/classes/java/main/iterative/Client.class index 4a61020a212f802f582fd9c3b955c937c146f7b5..c093a2380e617edb67de59d1229ddec35733b038 100644 Binary files a/build/classes/java/main/iterative/Client.class and b/build/classes/java/main/iterative/Client.class differ diff --git a/build/classes/java/main/iterative/IterativeServer.class b/build/classes/java/main/iterative/IterativeServer.class index 57adf30ba1c481adf952ff0828dcef4f72bbbcc8..78663cedfa10834eb996d64831d3cf24fff30432 100644 Binary files a/build/classes/java/main/iterative/IterativeServer.class and b/build/classes/java/main/iterative/IterativeServer.class differ diff --git a/build/classes/java/main/multithread/MultiServer.class b/build/classes/java/main/multithread/MultiServer.class index 6f33462f7cf9aca695339023b0e255fc6c2cfcdc..2f3f589b72262698d84e7e9d231b63d37572c05c 100644 Binary files a/build/classes/java/main/multithread/MultiServer.class and b/build/classes/java/main/multithread/MultiServer.class differ diff --git a/build/classes/java/main/multithread/ServerThread.class b/build/classes/java/main/multithread/ServerThread.class index 16b06dd85beca25fe594f7e739d1f829b88fde71..9fe3a1dc35be52b4a0b0c71be1b0f0c722019fc3 100644 Binary files a/build/classes/java/main/multithread/ServerThread.class and b/build/classes/java/main/multithread/ServerThread.class differ diff --git a/src/main/java/iterative/Client.java b/src/main/java/iterative/Client.java index d5f4ea4d7f74f1d395b7e34f4f628f4b8564b844..ca1cfd0880575d9ed108c788181a06494b9327a6 100644 --- a/src/main/java/iterative/Client.java +++ b/src/main/java/iterative/Client.java @@ -8,7 +8,7 @@ class Client { String sentence; String modifiedSentence; - // input stream initialization (from user keyboard) + /* Initialize input stream (from user keyboard) */ BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); @@ -17,24 +17,26 @@ class Client { 6789: server service port number */ Socket clientSocket = new Socket("localhost", 6789); - // output stream towards socket initialization + /* Initialize output stream towards the socket */ DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); - // input stream from socket initialization + /* Initialize input stream from the socket */ BufferedReader inFromServer = new BufferedReader( new InputStreamReader(clientSocket.getInputStream())); - // read a line from the user + /* Read an input line */ sentence = inFromUser.readLine(); - // send the line to the server + /* Send the line to the server*/ outToServer.writeBytes(sentence + '\n'); - // read the response from the server + /* Read response from the server (string ending with '\n') */ modifiedSentence = inFromServer.readLine(); System.out.println("FROM SERVER: " + modifiedSentence); + + /* Close the socket */ clientSocket.close(); } } diff --git a/src/main/java/iterative/IterativeServer.java b/src/main/java/iterative/IterativeServer.java index afddbb92902ed36ac4367ad1775961277b463f52..ca2e7b80351c800601afbd6b921efba369d73f00 100644 --- a/src/main/java/iterative/IterativeServer.java +++ b/src/main/java/iterative/IterativeServer.java @@ -8,34 +8,39 @@ class IterativeServer { String clientSentence; String capitalizedSentence; - // create a "listening socket" on the specified port + /* Create a "listening socket" on the specified port */ ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { - /* accept is a blocking call - once a new connection arrived, it creates - a new "established socket" */ + /* + * Call to accept function (blocking call). + * When a new connection arrives a new "established socket" is created + */ Socket connectionSocket = welcomeSocket.accept(); - // input stream from the socket initialization + /* Initialize input stream from the socket */ BufferedReader inFromClient = new BufferedReader( new InputStreamReader(connectionSocket.getInputStream())); - // output stream to the socket initialization + /* Initialize output stream towards the socket */ DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); - // read a line (that terminates with \n) from the client + /* Read a line (ending with '\n') from the client */ clientSentence = inFromClient.readLine(); - // wait for 10 seconds + /* simulate a processing time of 10 seconds*/ //Thread.sleep(10000); + /* Build the response */ capitalizedSentence = clientSentence.toUpperCase() + '\n'; - // send the response to the client + /* Send the response to the client */ outToClient.writeBytes(capitalizedSentence); + + /* Close the connection socket */ + connectionSocket.close(); } } }