01-19-2011 01:26 AM
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...
01-19-2011 01:48 AM
there is a limit on simulatanious connection open.
I will suggest that make sure you closed prev connections before open a new connection.
01-19-2011 01:53 AM
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.
01-19-2011 02:07 AM
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.
01-19-2011 04:37 AM
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.
01-19-2011 11:10 PM
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..