黑莓大胆的隧道失败。为什么?

时间:2021-04-14 02:26:27

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

我创建了一个j2me程序并将其移植到黑莓粗体。

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

该程序执行一些http查询。偶尔会出现例外情况:'隧道失败'

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

我的APN设置是正确的(因为有时它确实有效)。

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

我用'; deviceside = true'连接到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 个解决方案

#1


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

希望这可以解决你的问题

#2


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?

作为测试,您可能想尝试在URL本身上添加APN设置以查看是否有帮助。我猜你有很好的信号强度?

#3


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);

#1


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

希望这可以解决你的问题

#2


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?

作为测试,您可能想尝试在URL本身上添加APN设置以查看是否有帮助。我猜你有很好的信号强度?

#3


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);