hi guys, I've introduced this problem in Thread and synch forum that it seems this issue isn't solved by thread-related guys. the problem scenario is that I try to design and implement a simple server which shall service to many clients. well this guy listens on a port and waiting for requests, as core API it receives(parse) incoming requests as Socket object, which has an InputStream and OutputStream for communication, o yeah. as API says the incoming stream (InputStream) has a method read() which reads next byte of the incoming stream, and returns -1 when end of the stream is reached. so it's okay, but when I try to read the streams byte by byte, system will hangs on -1 value, I don't know it seems system waits for something. check the following code snipped
Rob, I've tried it with available() method and read(), and it works cool, well the problem is with incoming stream, the outputstream is okay, and mention that, the IOException will be thrown whenever the socket, incoming or, output stream is closed. the problem is looks solved till I find new issue of course. Thank you Rob, you mentioned an important point which a server application should care of it.
Thanks. I will reply this thread whenever I face with new issue.
Joined: Jan 13, 2009
Wow, new issue, Rob you said it right and mentioned an important point Thanks. as I said I face with new issue after find a solution. the combination of available and read method won't work(okay) for low-bandwidth connection. in fact it's not certain that incoming connection has stream or not. it requires something like wait(), I don't know, I introduced this problem with InputStreamReader class which has a method called ready() that take care of these problems for thread and synch guys. they told me there is not a standard way to synchronize the incoming stream, (using best solution wait and notify). now the problem is that server should wait for incoming stream and check it that it's empty or has content. for better understanding my issue imagine a HTTP server. any help, any solution, Thanks.