Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8129375

Error in "Reading from and Writing to a Socket"

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • None
    • None
    • docs
    • None

      In http://docs.oracle.com/javase/tutorial/networking/sockets/readingWriting.html

      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

      The second sentence should be "To get the server's response, EchoClient reads from the BufferedReader object in, which is created in the third statement in the try-with resources statment"

      This is because the stdIn object is used for reading the input from the standard-input, while the in object is used to read from the socket.

      Also fix the preceding paragraph:

      The second statement in the try-with resources statement gets the socket's output stream and opens a PrintWriter on it. Similarly, the third statement gets the socket's input stream and opens a BufferedReader on it. The example uses readers and writers so that it can write Unicode characters over the socket.

            rgallard Raymond Gallardo
            rgallard Raymond Gallardo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: