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
Regular Contributor
juszczec2
Posts: 59
Registered: ‎05-10-2012
My Device: 8800
My Carrier: verizon

InputStream.read() different behavior between OS v5 and v6......

Hi folks

 

My problem is code reading from a socket on v5 stops reading (no error or end of stream) while the same code on v6 continues processing.

 

See this link for further description:

 

http://supportforums.blackberry.com/t5/Java-Development/threading-problem-v5-vs-v6/m-p/1878375 


Up until yesterday, I've  been treating this as some kind of deadlock/race condition but now I'm not so sure.

 

The code reads from a socket using a Thread that uses InputStream.read() to read on e byte at a time.

On v5, at some point the read stops.  I presume because there's no data becuase there is no exception and the end of stream indicator (-1) has not been sent.  I have verified this with System.out.println's before and after the read.  I'll get the one before the read, but the one after the read never displays.

 

On v6, this does NOT happen.  Despite getting the same input, I always see the message before AND after the read.

I'm not sure why InputStream.read() works differently between os v5 & 6.  Does anyone know why?

More importantly, is there a way around this?  I do NOT want to block indefinitely as happens in OS v5 - I want the OS v6 behavior read and read and read and read and if there's no data return no data to the rest of the program and let it sort it out.

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: InputStream.read() different behavior between OS v5 and v6......

Do you see this behaviour on SImulators or only on device?

Please use plain text.
Regular Contributor
juszczec2
Posts: 59
Registered: ‎05-10-2012
My Device: 8800
My Carrier: verizon

Re: InputStream.read() different behavior between OS v5 and v6......

I've not tried it in the simulators.  I'm only testing on devices at this point.

 

I'm using a Curve as the os v6 device and a Bold as the os v5 device.

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: InputStream.read() different behavior between OS v5 and v6......

It would be useful to know if you can or cannot reproduce the problem on a Simulator.  Can you give it a try?

Please use plain text.
Developer
Dionysus
Posts: 152
Registered: ‎07-28-2011
My Device: Bold 9900
My Carrier: MTN

Re: InputStream.read() different behavior between OS v5 and v6......

Could you post a code snippet for how you are reading the data?

Please use plain text.
Regular Contributor
juszczec2
Posts: 59
Registered: ‎05-10-2012
My Device: 8800
My Carrier: verizon

Re: InputStream.read() different behavior between OS v5 and v6......

I've tried and can't get the app to run in the emulator.

 

I think I'm performing some operations that the emulator does not support.

 

For example, my code executes:

 

//load up permRequest

boolean acceptance = ApplicationPermissionsManager.getInstance().invokePermissionsRequest(permRequest);

 

But has some kind of runtime exception here.  When I comment that part out, the next the I try to do is access a web service which throws some kind of TLSIOException (I think, I didn't write it down).

 

Please use plain text.
Regular Contributor
juszczec2
Posts: 59
Registered: ‎05-10-2012
My Device: 8800
My Carrier: verizon

Re: InputStream.read() different behavior between OS v5 and v6......

Here's the guts of the ReadThread run method:

while
(mInputStream != null) {

 

 System.out.println("ReadThread.run() before read mInputStream.available()="+mInputStream.available());

 int ch = mInputStream.read();

 System.out.println("ReadThread.run() after read ch="+ch);

 if (ch >= 0)

     insert(ch);

 else

 {

      sleep(500);

      break;

 }

}

 

On v5 this line:

 

int ch = mInputStream.read();

never returns control back to me.

 

mInputStream.available() has proven to be unreliable.

 


 

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: InputStream.read() different behavior between OS v5 and v6......

The issues you have described should not stop the app running on the Simulator. 

 

As I find the Simulator so much easier to use a debug, I will code

if (DeviceInfo.isSimualtor() ) { ... }

to makes rue it will run.

 

I don't understand the ApplicationPermission since you App should have permission anyway in the SImulator.  Regarding the network connection, use ";deviceside=true".

 

This is interesting:

TLSIOException

Are you running an SSL connection?

Please use plain text.
Regular Contributor
juszczec2
Posts: 59
Registered: ‎05-10-2012
My Device: 8800
My Carrier: verizon

Re: InputStream.read() different behavior between OS v5 and v6......

I'll take another look at where I'm hanging up in the debugger and try DeviceInfo.isSimulator() as you suggest.

 

The network connection is using deviceside=true and yes, it is an SSL connection.

 

Does SSL throw some extra wrinkle into this?

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: InputStream.read() different behavior between OS v5 and v6......

"The network connection is using deviceside=true"

 

That should work fine on the Simulator. 

 

"Does SSL throw some extra wrinkle into this?"

 

A very good question, I am really not sure.  It must change the OS processing for the connection establishment and presumably for the encryption as the data is sent.  But is your problem is this part of the OS code?  We don't know do we?  Not even sure how to tell!

Please use plain text.