Hi
I am quite new to bb. Currently I am using the the model 8100 pearl for testing the developed code.
In my application I need to establish HttpConnection or StreamConnection successfully. I need to give the parameters of APN settings in the code itself, without manually entering the APN settings in the phone. Therefore I have cleared all the APN settings in the phone.
I am using J2ME for development and I have written the following code segment.
HttpConnection connection = null;
InputStream stream = null;
StringBuffer b = new StringBuffer();
try {
connection = (HttpConnection)Connector.open("http://www.google.com/"+";WAPGatewayIP=<IP>"+";WapGatewayAPN=<APN>") ;
stream = connection.openInputStream();
boolean firstItr = true;
int test=0;
int ch;
while ((ch = stream.read()) != -1) {
b.append((char) ch);
if(firstItr){
test = ch;
firstItr = false;
}
}
Form form = new Form("Test");
form.append(b.toString());
Alert aleart = new Alert(null,"Connection successful
\n"+test, null, AlertType.INFO);
aleart.setTimeout(1000);
Display.getDisplay(this).setCurrent(aleart,form);
stream.close();
connection.close();
System.out.println("connection closed");
destroyApp(false);
} catch (IOException e) {
Alert aleart = new Alert(null,"Connection unsuccessful
"+e.toString(), null, AlertType.ERROR);
aleart.setTimeout(1000);
Display.getDisplay(this).setCurrent(aleart);
}
That is the code i have written. Sometimes the connection establishment throws no exceptions but it doesnt give out any data. The method
'stream.read()' returns
-1 always.
At some instances the connection does not establish successfully and throws an open tunnel IOEXception.
Please help me to overcome this issue. I will be very greatful a is anyone can help me in this.