jQuery in Action, 2nd edition*
The moose likes Sockets and Internet Protocols and the fly likes parsing incoming socket stream, InputStream. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "parsing incoming socket stream, InputStream." Watch "parsing incoming socket stream, InputStream." New topic
Author

parsing incoming socket stream, InputStream.

Zaeed McColin
Ranch Hand

Joined: Jan 13, 2009
Posts: 90
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

the D part: the problem is raised here, it seems it reaches -1 but doesn't return it., bty I've tried this guy with everything you think, I tested it with InputStreamReader, DataInput,... many things. did I use incorrectly of InputStream? any solution,.. thanks.
the following link may help too, (my session with Thread guys)
http://www.coderanch.com/t/488556/Threads-Synchronization/java/reader-interface-wait-then-go


Open source
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Is the client socket (or at least its output stream) closed? Because if it's not then how do you know that the stream has ended? Maybe the client still needs to send information.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Zaeed McColin
Ranch Hand

Joined: Jan 13, 2009
Posts: 90
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.
Zaeed McColin
Ranch Hand

Joined: Jan 13, 2009
Posts: 90
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: parsing incoming socket stream, InputStream.
 
Similar Threads
server can not accept all the clients connection request
Socket : MultiClient Server
Java net BindException:Address already in use: JVM_Bind
parsing incoming socket stream.
reader interface, wait() then go