tunnel failed in blackberry bold. why?

2019-05-31 17:09发布

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.

3条回答
Emotional °昔
2楼-- · 2019-05-31 17:54

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?

查看更多
forever°为你锁心
3楼-- · 2019-05-31 18:07

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);
查看更多
The star\"
4楼-- · 2019-05-31 18:13

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

查看更多
登录 后发表回答