View Single Post
Old 05-17-2011, 05:36 AM   #1 (permalink)
maykivets
New Member
 
Join Date: May 2011
Model: Curve
PIN: N/A
Carrier: Kyivstar
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default wifi: works in browser and apps, but not in our program

Please Login to Remove!

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)Connector.open(getUrl() +";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 = input.read(data)) )
{
// Exit condition for the thread. An IOException is
// thrown because of the call to httpConn.close(),
// causing the thread to terminate.
if ( _stop )
{
httpConn.close();
s.close();
input.close();
}
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());
}
input.close();
}
else
{
content = "response code = " + status;
}
s.close();
}
catch (IOCancelledException e)
{
System.out.println(e.toString());
return;
}
catch (IOException e)
{
errorDialog(e.toString());
return;
}
Offline   Reply With Quote