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

socket read fails if done too soon.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P2 P2
    • None
    • 1.0
    • core-libs
    • sparc
    • generic

      ------------- Begin Forwarded Message -------------

      From daemon@java Sun Oct 1 18:40 PDT 1995
      To: java-interest@java
      Subject: sockets and input streams?

      I have a class which contains a java.net.Socket and obtains
      the in/out streams from getInputStream/getOutputStream etc.

      my class has a write() and read() methods which operate on
      byte[]'s. Obviously my write uses the out stream and read
      use the in stream, etc.

      While doing a quick test of my class I open a connection to
      a server which will echo back what ever data is sent to it.

      So my test simply writes a 4 byte array which contains "abc" and
      then immediately does a read. The read was returning a -1.
      after some time I stuck a Thread.Sleep(x) between the write and
      read. For x >= 10 this makes the program work. I tried x=1 that
      still failed (returned -1).

      I excpected the read on the input stream to block until data
      was available (as the docs say). However, it returns a -1
      indicating the end of the stream? What is going on here?

      The Sleep should not be a valid solution.

      ..........larry
      -
      Note to Sun employees: this is an EXTERNAL mailing list!
      Info: send 'help' to ###@###.###
      ------------- End Forwarded Message -------------

            duke J. Duke
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: