BlackBerry Forums Support Community

BlackBerry Forums Support Community (
-   Developer Forum (
-   -   wifi: works in browser and apps, but not in our program (

maykivets 05-17-2011 05:36 AM

wifi: works in browser and apps, but not in our program
Hello everyone,

we have just started to write Blackberry apps and got strange situation. Our apps work with mobile internet (GPRS, 3G, EDGE) but are not working using wifi connection.

I have tried to change all the settings. But still usually it is just "Tunnel failure" or "connection timed out". The same is with HTTPDemo example.

Could someone help and explain what it is with Blackberry and WiFi?

StreamConnection s = null;
s = (StreamConnection) +";interface=wifi");
HttpConnection httpConn = (HttpConnection)s;

int status = httpConn.getResponseCode();

if (status == HttpConnection.HTTP_OK)
// Is this html?
String contentType = httpConn.getHeaderField(HEADER_CONTENTTYPE);
boolean htmlContent = (contentType != null && contentType.startsWith(CONTENTTYPE_TEXTHTML));

InputStream input = s.openInputStream();

byte[] data = new byte[256];
int len = 0;
int size = 0;
StringBuffer raw = new StringBuffer();

while ( -1 != (len = )
// Exit condition for the thread. An IOException is
// thrown because of the call to httpConn.close(),
// causing the thread to terminate.
if ( _stop )
raw.append(new String(data, 0, len));
size += len;

raw.insert(0, "bytes received]\n");
raw.insert(0, size);
raw.insert(0, '[');
content = raw.toString();

if ( htmlContent )
content = prepareData(raw.toString());
content = "response code = " + status;
catch (IOCancelledException e)
catch (IOException e)

hrbuckley 05-17-2011 08:21 AM

Re: wifi: works in browser and apps, but not in our program
Ok, first please read this post so the code you post will be easier to read.

1. What OS version are you using?

2. Do you have a BlackBerry Data Plan on the device?

3. Have you configured the appropriate APN values for your carrier?

maykivets 05-17-2011 09:23 AM

Re: wifi: works in browser and apps, but not in our program
Here are the answers to your questions:
1. 5.0
2. It works now even without Data Plan (with the code below).
3. Is it really necessary for the wifi connections?

PHP Code:

HttpConnection connection 
if (
connection = (";interface=wifi",
} else {
connection = (";deviceside=true"Connector.READ_WRITE,true);

hrbuckley 05-17-2011 04:58 PM

Re: wifi: works in browser and apps, but not in our program
Glad to hear you got it working.

2. Depending on the carrier and the OS level Wi-Fi won't work without one.
3. No, but again, depending on the OS level and carrier support the else clause from your code above won't work without the APN configured, usually the earlier OSes need an APN.

All times are GMT -5. The time now is 01:17 AM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.