I was going through the Java TCP Client Server tutorials where they are explaining how a echo server works and how a TCP client interacts with the echo server.
For the TCP Client, they have given this snippet and are explain what it is:
String hostName = args[0];
int portNumber = Integer.parseInt(args[1]);
try (
Socket echoSocket = new Socket(hostName, portNumber);
PrintWriter out =
new PrintWriter(echoSocket.getOutputStream(), true);
BufferedReader in =
new BufferedReader(
new InputStreamReader(echoSocket.getInputStream()));
BufferedReader stdIn =
new BufferedReader(
new InputStreamReader(System.in))
)
later on, a few lines below (around 8 lines) they say:
To send data through the socket to the server, the EchoClient example needs to write to the PrintWriter. To get the server's response, EchoClient reads from the BufferedReader object stdIn, which is created in the fourth statement in the try-with resources statement.
Why does it say that
To get the server's response, EchoClient reads from the BufferedReader object stdIn
Isn't stdIn
used for reading from the System's standard input and not the socket's standard input? Should the Echo client read from the in
BufferedReader?
If I am wrong, could you clarify my misunderstanding?
http://docs.oracle.com/javase/tutorial/networking/sockets/readingWriting.html
Edit
Maybe I wasnt clear enough. When the client has to get data from the server. Does it get it form this:
BufferedReader in =
new BufferedReader(
new InputStreamReader(echoSocket.getInputStream()));
or this:
BufferedReader stdIn =
new BufferedReader(
new InputStreamReader(System.in))
The doc says from the second one. That doesn't make sense, it should be the first one