Commit 2ae34c4c authored by Michele Fiori's avatar Michele Fiori

Minor changes

parent 53b573d1
......@@ -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();
}
}
......@@ -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();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment