[2429] in java-interest

home help back first fref pref prev next nref lref last post

sockets and input streams?

daemon@ATHENA.MIT.EDU (Larry Reu)
Sun Oct 1 23:41:58 1995

Date: Sun, 1 Oct 1995 18:28:32 -0700 (PDT)
From: Larry Reu <larryr@CyberGate.COM>
To: java-interest@java.sun.com

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 java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post