0

I've read a lot posts on the web, but I haven't found solution.

I've developed a BlackBerry App ( SDK 5 ) that's using HttpConnection to get/set data from server.

I tried to connect via Wireless and G2/G3 connection.

In both cases Application works fine for some time and then suddenly internet connection breaks (sometimes in the middle of the loading data from the server). After that happens Application doesn't work and I also can't go to any web page (in BB Browser). It looks like BB disables internet.

When I try it in BB Browser I get the following message:

Unable to connect to the Internet please try again later. If the problem persists please contact your service provider

The only way to get the internet back is to go to settings and disable WiFi and then re-Enable it again. After that it works, but again for some time.

It never breaks at the same point.

Here is the code that I'm using to get data from the server:

String urlPath = "http://www.mysite.com/api/?debug=true";
//debug is my variable on the site, it's not necessary

if(DeviceInfo.isSimulator()){
    urlPath += ";deviceside=true";
} else {
    if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
        urlPath += ";interface=wifi";
    }else{
        urlPath += ";deviceside=true";
    }
}

HttpConnection httpConn = (HttpConnection) Connector.open( urlPath );

httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
httpConn.setRequestProperty("Content-Language", "en-US");
httpConn.setRequestProperty("Connection", "close");

OutputStream os = httpConn.openOutputStream();

os.write(temp1.getBytes());
os.flush();
os.close();
StringBuffer sb = new StringBuffer();
DataInputStream is = httpConn.openDataInputStream();
int chr;
while ((chr = is.read()) != -1) {
    sb.append((char) chr);
}

String response = new String(sb.toString().getBytes(), "UTF-8");

What am I doing wrong?

Is there a way to fix this and keep the connection stable and responsive?

Thanks.

Surender Thakran
  • 3,958
  • 11
  • 47
  • 81
  • 1
    You should use the new `ConnectionFactory` class instead of harcoding the suffixes yourself. As for the connectivity problem, does it happens with every device or is a problem of a single device in particular? – Mister Smith Jun 05 '12 at 12:59
  • btw. In simulator App works great, this only happens on real device. – user1437097 Jun 05 '12 at 13:00
  • @MisterSmith I have only tested it on BlackBerry Bold 9000. I'll try it with ConnectionFactory class. – user1437097 Jun 05 '12 at 13:02
  • @MisterSmith thank You for the advice to use ConnectionFactory Class, now application works without setting connection parameters manually, but still at some point the Internet connection breaks / gets disabled. I don't know where the problem is. The code that I posted before is the only piece of code that I use to get data from the Internet and it is inside the thread. Is it possible that there is something wrong with the phone or is it the problem with my application? – user1437097 Jun 06 '12 at 13:06
  • You could test it on different real devices to see if it is a hardware or configuration problem. And you could also try to use a different server to make sure the server isn't dropping the connection. – Mister Smith Jun 11 '12 at 07:10

0 Answers0