aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes available() method returning zero Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "available() method returning zero " Watch "available() method returning zero " New topic
Author

available() method returning zero

Michael Monchu
Greenhorn

Joined: Oct 20, 2010
Posts: 16
Hi

I am the first time on the forum and I am having a problem with retrieving the data from the InputStream. I have a Client program that sends the data to the ISeries Server and get a response and display it on a Web page. The problem is that when I run the program interactively, the available method returns zero, but when run in a debug mode, the available() returns the expected number of bytes. Can someone help me in explaining why the method would work only in a debug mode. Below is the source code used to read the data from the socket.



Please let me know if you need more information regarding this.

Thanks in advance.

Michael

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
See this: AvailableDoesntDoWhatYouThinkItDoes.

Probably, in debug mode your code is running more slowly (especially if it's waiting for you to press buttons to step through something) and thus, whatever process is responsible for making bytes available has more time to achieve this. When you're not in debug mode, the code runs faster, and it goes through that code before bytes are actually available. Avoid using available(); it's fundamentally useless.
Michael Monchu
Greenhorn

Joined: Oct 20, 2010
Posts: 16
I changed the code not to use the available(), and I'm glad to tell you that it's working perfectly.

Thanks a lot for your assistance.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: available() method returning zero