Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 47
Registered: ‎05-06-2009
My Device: Not Specified

Re: another socket problem: socket is not receiving although it is ready

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 Smiley Very Happy

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: another socket problem: socket is not receiving although it is ready

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.

Contributor
Posts: 12
Registered: ‎02-15-2010
My Device: 7100t
My Carrier: Airtel

Re: another socket problem: socket is not receiving although it is ready

[ Edited ]

Hey,

Thanks the suggestion of using InputStream rather than InputStreamReader really works out in a socket connection problem....

Highlighted
Contributor
Posts: 10
Registered: ‎10-15-2011
My Device: BlackBerry Bold
My Carrier: xxx

Re: another socket problem: socket is not receiving although it is ready

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"