10 Replies Latest reply: Nov 7, 2007 10:39 PM by 807603 RSS

    What is ASCII character for end of stream?

    807603
      I googled but failed to find the answer. Is it 004/EOT, 027/ETB, or something else?

      In socket, read() != -1 never be reached, which incurred my above question. I want to see what ascii is used to indicate end of stream.

      Thanks!
        • 1. Re: What is ASCII character for end of stream?
          807603
          There is no character (ASCII or otherwise) that indicates end-of-stream.
          • 2. Re: What is ASCII character for end of stream?
            807603
            http://java.sun.com/javase/6/docs/api/java/io/InputStream.html#read()

            <quote>
            Returns:
                     the next byte of data, or -1 if the end of the stream is reached.
            </quote>
            • 3. Re: What is ASCII character for end of stream?
              DrClap
              kkus wrote:
              In socket, read() != -1 never be reached, which incurred my above question. I want to see what ascii is used to indicate end of stream.
              That's because whatever is sending the data hasn't closed the socket yet. When it does, your code will get -1.

              But if your protocol doesn't include closing the socket (for example because you want to transmit files repeatedly) then it will have specified a way of determining that the entire file has been sent. Use that way instead of waiting for -1.

              Or if your protocol doesn't specify that, and you need to keep the socket open, then it wasn't designed correctly.
              • 4. Re: What is ASCII character for end of stream?
                807603
                So, when socke.close() is invoked, do you know what ASCII is sent through socket's outputStream? There must be an ASCII to indicate end of stream for close(), otherwise how the other party's inputStream.read() detect it reaches an end of stream? read() should check something to determine socket is close. What is something here?
                • 5. Re: What is ASCII character for end of stream?
                  807603
                  You need to rethnk the way that you reason about behavior and how you ask questions.
                  There must be an ASCII to indicate end of stream ... otherwise how [does it] detect ... end of stream?
                  It looks to me like the question you are trying to ask is:
                  "How does one socket tell another that it has reached an end of stream?"

                  There's a mechanism there - youre just assuming its ASCII or that some sentinel value is sent.
                  ASCII is a text encoding. Since youre talking about a communications protocol were talking
                  binary. Theres no reason to call it ASCII.

                  It could be somthing as simple as: I know how many bytes long the message is and ive read
                  that many bytes.
                  • 6. Re: What is ASCII character for end of stream?
                    807603
                    kkus wrote:
                    So, when socke.close() is invoked, do you know what ASCII is sent through socket's outputStream? There must be an ASCII to indicate end of stream for close(), otherwise how the other party's inputStream.read() detect it reaches an end of stream? read() should check something to determine socket is close. What is something here?
                    Who cares hows it's implemented?
                    • 7. Re: What is ASCII character for end of stream?
                      EJP
                      There must be an ASCII to indicate end of stream for close(), otherwise how the other party's inputStream.read() detect it reaches an end of stream?
                      The end-of-stream indication is sent out-of-band so as not to restrict the 255 byte values that can be sent. End of stream is indicated by the FIN bit being set in a TCP segment header.
                      • 8. Re: What is ASCII character for end of stream?
                        807603
                        ejp wrote:
                        There must be an ASCII to indicate end of stream for close(), otherwise how the other party's inputStream.read() detect it reaches an end of stream?
                        The end-of-stream indication is sent out-of-band so as not to restrict the 255 byte values that can be sent. End of stream is indicated by the FIN bit being set in a TCP segment header.
                        Ah, now I can sleep at night :-)
                        • 9. Re: What is ASCII character for end of stream?
                          EJP
                          err, 256 byte values, 0..255.
                          • 10. Re: What is ASCII character for end of stream?
                            807603
                            ejp wrote:
                            err, 256 byte values, 0..255.
                            Zzzz... huh? Oh yeah... Zzzz....