------------- 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 -------------
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 -------------