02-08-2010 02:23 PM
I've read about that problem.
Does the written case (it returns zero with data available) happen randomly?
What can I use instead of that? If possible something non-blocking would be good, so I don't have to use another thread which could cause problems
02-08-2010 02:33 PM
It's not random, it's just that the contract of InputStream.available() doesn't really say that 0 means no data can be read without blocking. Basically, all it really says is that InputStream.available() returns a lower bound for the number of bytes that can be read without blocking. It's completely fine to always return 0 even if there are data that can be read without blocking.
Unfortunately, there is no non-blocking network I/O API exposed to third-party applications on BlackBerry. All you can do is use the blocking read/write methods while either setting a read/write timeout on the connection (which is not supported on some old platforms) or periodically check some timeout value from another thread (e.g., daemon thread, Timer, event dispatcher) and disconnect once the timeout expires.
04-27-2010 03:10 AM - edited 04-27-2010 03:12 AM
Thanks the suggestion of using InputStream rather than InputStreamReader really works out in a socket connection problem....
11-19-2011 06:58 AM
Hey I have tried the same code for reading through InputStream.read()
but its gives an error "Cannot make a static reference to the non-static method read() from the type InputStream"