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
arvbhavan
Posts: 50
Registered: ‎12-11-2010
My Device: nil

Httpconnection from thread causes random errors

hii all..

I am using httpconnection to download images from a remote server.And in my application there are 20 or more images to be downloaded. When i start my application for the first time, mostly i am able to run the application.But when its second or third time i am gtting some error message and the images are not properly downloaded. I get messages like stream closed. TCP error(getting very rarely).

 

Why this happens the app works correctly on simulator..????

 

Is it because in the thread i am using multiple http connections to download the images..So each connection starts before the first one completes...If the error is happening due to this case how can i run the app for the first time without any error..

 

 

Any replies please...

Please use plain text.
Developer
vivart
Posts: 147
Registered: ‎08-27-2010
My Device: 9800
My Carrier: airtel

Re: Httpconnection from thread causes random errors

there is a limit on simulatanious connection open.

 

What Is - Maximum number of simultaneous connections

 

I will suggest that make sure you closed prev connections before open a new connection.

Please use plain text.
Regular Contributor
arvbhavan
Posts: 50
Registered: ‎12-11-2010
My Device: nil

Re: Httpconnection from thread causes random errors

Maximum connections are some 20...But i tried limiting the connection to two(2) this also failed when i tried it some two three times.ie the app worked ine for the first two times and then failed. sometimes iam getting  timed out exception also.

Please use plain text.
Regular Contributor
arvbhavan
Posts: 50
Registered: ‎12-11-2010
My Device: nil

Re: Httpconnection from thread causes random errors

One more thing, since i am using thread. The threads run method is called almost simultanoeusly so soon after opening one connection next threads run is called and opens other connection.

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

Re: Httpconnection from thread causes random errors

Two points to think about:

 

1) Connections can be broken for any number of reasons, such as moving out of coverage, taking a phone call on a non 3G connection.  Are you sure what you are seeing is not just the result of chance?  Your downloads are going to fail sometimes, you need to put logic in to retry them.

 

2) Have you thought of creating a 'Server' model where you have a pool of download Threads waiting for work - you add work to a queue for these Threads to process?  That way you can easily control the number of active Threads. 

Please use plain text.
Regular Contributor
arvbhavan
Posts: 50
Registered: ‎12-11-2010
My Device: nil

Re: Httpconnection from thread causes random errors

The problem occurs while reading the inputstream to a byte array.

 

When i debug by attching my device it seems that it works fine for reading the images the first one two times and then throws exception while i tried to read the input stream data.

 

The exception thrown is Stream closed exception..

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

Re: Httpconnection from thread causes random errors

Just wondering, what does the server say?

Please use plain text.