views:

1679

answers:

3

Hi,

I created a j2me program and ported it to the blackberry bold.

The program does some http queries. Every now and then these fail with the exception: 'tunnel failed'

My APN settings are correct (since sometimes it does work).

I connect with ';deviceside=true' appended to the url

I notice that when the browser has just been active, the program always works. However when the browser hasn't been active for some minutes and I start the program, I get the tunnel failed errors.

Anyone suggestions? This is driving me mad!

R

A: 

As a test, you might want to try adding the APN settings on the URL itself to see if that helps. I assume you have good signal strength?

Marc Novakowski
yes signal strength is great. I'll try if the apnsettings in the url helps. Although of course for a final solution this is highly undesirable ;^)
Toad
It may be undesirable but if you are releasing your app into the public, you're going to have to do it that way. While some carriers may configure newer devices such as the Bold with an APN from the factory, it's not guaranteed to be set. Older devices such as the Curve and Pearl almost never have it set.
Marc Novakowski
A: 

As silly as this sounds even if you are only reading from the connection, make sure when opening the connector you open it as read/write

String url = "http://www.google.com"; HttpConnection connection = (HttpConnection)Connector.open(url, Connector.READ_WRITE, true);

kgutteridge
yes! I already had this in my code. I read somewhere that a POST does work with some tunnel failed errors and GET doesnt. The trick it seemed was to upen with READ_WRITE in all cases.
Toad
+1  A: 

The problem with a few blackberry devices is that every other network connection fails. So you will have to try it once more when you receive an exception. So your connection code should be something like this

int numAttempts = 0;
boolean hasConnectedSuccessfully = false;
while(numAttempts < 2 && !hasConnectedSuccessfully)
{
   try
   {
     // do the http connection
      hasConnectedSuccessfully = true;
   }
   catch(Exception e)
   {
      hasConnectedSuccessfully = false;
   }
   finally
   {
     //close the connections
   }
   numAttempts++;
}

Hope this should fix your problem

Ram
i think you missed out the upcount for numAttempts :)
Andreas Niedermair
Thanks dittodhole, corrected
Ram
uUnfortunately it fails every time.... until I open the browser in the background.. after which it will succeed for the next 5 minutes
Toad
Just look out for details about the connection strings that you might have to append while making http connections, it would be MDS, BISB and devicetcp. Check the Blackberry forums for the details. I dont exactly remember the connection string that needs to be appended at the end of the url that you are attempting to connect to
Ram
Basically, the connection string is just to tell which of those to be user either MDS, BISB or Device TCP. Usually you use MDS first and if that fails, you go in for BISB and then for DeviceTCP. Hopefully, the browser seems to be using one of these, so that the device knows that it has to use those settings when an http connection is made. Hope this helps
Ram
actually no.... do you have a snippet how to achieve something like this?
Toad