Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Christophe
Posts: 39
Registered: ‎07-21-2008
My Device: Many

TCP Connection problem on 9000 bold

Hi,

I'm trying to deploy my application to the Blackberry 9000 bold. I got a tcp connection problem.

java.io.IOEXception: connection not writeable
over 3G (note the extra "e")

and
java.io.IOEXception: tunnel failed
over my wifi


Note:
- the application work fine on BB 8100/8300
- the browser work over both 3G and wifi (with the other one turned off).
- I did register the device under "Options > Advanced Options > Host Routing Table > Register Now."
- I did compile it with the rapc v 4.6 and sign it.


I did make the try/search I could think of... and ... well no result. I'm stuck.

So, any help/idea or feedback about this problem will be greatly appreciated.


Christophe

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: TCP Connection problem on 9000 bold

Couple of minor points:

1) In my experience, there is no need to recompile to get network code working on the Bold. 

2) In the UK, you can just add ":interface=wifi" to the connection string and use the Bold's WiFi, with or without a sim installed.  However your mileage might vary elsewhere in the world.

 

To investigate this problem, I think we are going to need a little more.  Can you tell us:

a) What carrier you are using

b) What connection string you are using to force 3G and WiFi

c) What sort of user you are (BES or BIS)

Developer
Christophe
Posts: 39
Registered: ‎07-21-2008
My Device: Many

Re: TCP Connection problem on 9000 bold

Hi Peter,

thanks for your answer.

1)
a.
I did try with my old compilation (4.2.1) :  same result. (but msg diff: "Connection not readable")

b.
In most cases, I agree with you (meaning by experience), but Since RIM say explicitly that there is no backwards compatibility (meaning the app MUST be compiled with a compiler at least the same version number as the platform).

I did try with version 4.6 anyway.


2) Thanks for the info.


About your questions:

a) I try with Vodafone ES, but I doubt this is the problem. The application works fine with this carrier (and ORange ES) on a 8130-Curve and on a 8100-Perl.

b) None, I just turn off the phone and turn on the wifi (and vice-versa). (with connection management)

c) I m not behind a BES.


---------------

Something I did not specify:

- I did implement a POST method to call my phps.
something like:
                  connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                  // POST content type
                 
                  outputstream = connection.openOutputStream();
                 
                  requestParam += "\r\n";
                  outputstream.write( requestParam.getBytes());
                 
- this works fine with the 9000 simulator                 
                 

BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: TCP Connection problem on 9000 bold

You can use a lower version of the BlackBerry JDE to build an application.

 

What Is - Appropriate version of the BlackBerry JDE
Article Number: DB-00537

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800901/What_Is_-_Appr...

 

Since you are not on a BlackBerry Enterprise Server, you can create a direct TCP connection, Wi-Fi connection or WAP gateway connection. 

 

If you are trying to use direct TCP, have you filled out the APN information for your carrier under Options, Advanced Options, TCP and verified the SIM card you are using has access to this APN?

 

If you are using Wi-Fi, please verify that the BlackBerry Bold is connected to a Wi-Fi network under Options, Wi-Fi.

 

You can see an overview of the different connection routes available here:

 

What Is - Different ways to make an HTTP or socket connection
Article Number: DB-00396

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Christophe
Posts: 39
Registered: ‎07-21-2008
My Device: Many

Re: TCP Connection problem on 9000 bold

hi,

 

thanks for your answer.

 

I doubt it is a configuration issue, since the browser work fine with the same device config. (APN & Wi-fi)

 

(As I know, the browser use the same config as the TCP connection when you are not using a BES. right?)

 

 

 

about your answer:

 

I don't know if I am very clear, but my goal is NOT to select the connection type.

 

My goal is (just) to make a (any) http connection with the Bold.

 

I tried to compile with the rapc version 4.6 because it was NOT working with the 4.2.1.

I tried with wifi because I thought it could be a APN related issue.

 

 

It may be an implementation problem. but I will be surprise since i use the same code for over 6 month now. And it's working fine on 8100 & 8310. this is why I assume it as something to do with the 9000.

 

If you think it's an implementation problem, I can post you my code to have a look at.

 

thanks for your time,

 

 

Developer
Christophe
Posts: 39
Registered: ‎07-21-2008
My Device: Many

Re: TCP Connection problem on 9000 bold

Hi, I made more test, and this is what I came with.

When doing http GET connection on Bold : the platform return an error. (This was the first connection of my application)

With POST it is working fine.

More funny, I found out that the GET request work on https server.

so...  I start to think this has something to do with How I open the connection.
maybe a header is missing?

anyways... Here is my code that open the connection. This is called by the "pop" a syncronized queue running in a separated thread.

I hope somebody can see what I do wrong... Or confirm me that he have the same problem on his Bold. (This is working on Perl/Curve)

thanks in advance,


private void doSend(String request)
{
boolean wasError = false;
int errorCode = -1;
int returnCode = -1;
String errorStr = "";
String ContentType = "";
byte[] responseByte = null;


HttpConnection connection = null;
InputStream inputstream = null;

//for POST
OutputStream outputstream = null;
String requestParam="";
int i;

try {
if (post_nGet){

//extract param from the URL (query string)
i = request.indexOf('?');
if (i>0){
requestParam = request.substring(i+1);//+1 : del the '?'
//Trace("requestParam = " + requestParam );
request = request.substring(0, i);
//Trace("request = " + request );
}

connection = (HttpConnection) Connector.open(request, Connector.READ_WRITE, true);
connection.setRequestMethod(HttpConnection.POST);

} else {

connection = (HttpConnection) Connector.open(request, Connector.READ, true);
//Note : the jvm will create the good kind of connection (http vs https) object in fct of the url.
connection.setRequestMethod(HttpConnection.GET); //default

}

// send the session cookie.
if (serverSession!=null && !"".equals(serverSession)){
connection.setRequestProperty("Cookie", serverSession);
}

if (post_nGet && !"".equals(requestParam) && requestParam!=null){
// add the POST param in the Http request *body*

connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// POST content type

//connection.setRequestProperty("Content-Length", "" + (requestParam.length())); do NOT include this line. not necessary. length added by lib.

outputstream = connection.openOutputStream();

requestParam += "\r\n";
outputstream.write( requestParam.getBytes());

//outputstream.flush();
//this line may bring some problem (fct of the device)
// (Transfer-encoding : chunked --> not supported by all web server
}


//connection.setRequestProperty( "User-Agent", "Xxx" );

// we will use the default device user Agent.
//connection.setRequestProperty( "Content-Language", "en-US" ); useless

//NOTE: call to getResponseCode open the connection
returnCode = connection.getResponseCode();

if (returnCode == HttpConnection.HTTP_OK) {
ContentType = connection.getHeaderField("Content-Type");

// Read the session ID from a cookie in the response headers.
// /!\ we made some supposition here /!\ (only one cookie)
String cookie = connection.getHeaderField("Set-Cookie");
if (cookie != null) {
serverSession = cookie.substring(0, cookie.indexOf(';'));
//Trace("serverSession = " + serverSession );
}


inputstream = connection.openInputStream();


int length = (int) connection.getLength();
int lengthRead;
int lengthRead2sd;
//Trace("length receive (Http) : " + length);
if (length != -1) {
responseByte = new byte[length];
lengthRead = inputstream.read(responseByte);
//Trace("length read (Http) : " + lengthRead);

while (lengthRead < length){
//Trace("lengthRead < length : missing "+(length-lengthRead));
lengthRead2sd = inputstream.read(responseByte, lengthRead, length-lengthRead);
if (lengthRead2sd <=0){
//Trace("lengthRead2sd <=0 ; missing : " +(length-lengthRead) );
break;
}
lengthRead += lengthRead2sd;
}

} else {
ByteArrayOutputStream bytestream =
new ByteArrayOutputStream();
int ch;
while ((ch = inputstream.read()) != -1) {
bytestream.write(ch);
}
responseByte = new byte[bytestream.size()];
responseByte = bytestream.toByteArray();
bytestream.close();
}
}else{
wasError = true;
errorCode = returnCode;
errorStr = errorMessage(returnCode);
}

} catch(Exception error) {
wasError = true;
if (error instanceof CertificateException){
errorCode = 6;// Certif error.
errorStr = "" + error;
} else {
errorCode = 1;// unknow
errorStr = "" + error;
}
} finally {
if (inputstream!= null) {
try {
inputstream.close();
} catch( Exception error) {
wasError = true;
errorCode = 2;
errorStr = "" + error;
}
}
if (connection != null) {
try {
connection.close();
connection=null;
System.gc();
} catch( Exception error) {
wasError = true;
errorCode = 3;
errorStr = "" + error;
}
}
if (outputstream != null){
try {
outputstream.close();
outputstream=null;
System.gc();
} catch( Exception error) {
wasError = true;
errorCode = 4;
errorStr = "" + error;
}
}
}

if (wasError)
{
httpListener.handleHttpError(errorCode, errorStr);
}
else
{
httpListener.receiveHttpResponse(responseByte, ContentType);
}
}

 

Developer
udik
Posts: 136
Registered: ‎03-04-2009
My Device: Not Specified

Re: TCP Connection problem on 9000 bold

Hi Christophe,

 

Did you ever find the solution to this issue? I have exactly same problem with Bold ...

 

Thanks!

Udi

 

Developer
Christophe
Posts: 39
Registered: ‎07-21-2008
My Device: Many

Re: TCP Connection problem on 9000 bold

Hi Udik,

 

I'm glad somebody could confirme me this problem.

 

and, No. I did not found a real solution.Sorry.

 

But I use POST or GET with SSL depending the application.This is working fine.

 

Please ask BB support to motive them to make a real fix.

 

 good luck,

 

Christophe

 

 

New Developer
sherpa99
Posts: 1
Registered: ‎09-17-2009
My Device: Not Specified

Re: TCP Connection problem on 9000 bold

Hi,

 

I encountered the same problem. 

 

The app did work fine until I used the bb bold with BIS.

 

One remarkable Detail. Right after installung the application I was able to run the application. There was definitly a connection to the APN.

 

But this worked exactly just right after installing and running the app the very first time. At the second start there was the error message.

 

Is there any solution you know about

 

regards

sherpa

Developer
aykarthik
Posts: 187
Registered: ‎08-13-2008
My Device: Not Specified

Re: TCP Connection problem on 9000 bold

Hi Guys,

 

I am also facing the same issue.

 

I tried to access Direct Tcp socket connection with the following url in BB STORM.

 

socket://www.google.ca/search?q=blackberry;deviceside=true 

 

It says tunnel failed.

 

I have set the apn details under Options->Advanced Options->Tcp/Ip. I can able to access browser and download applicaions. 

 

Carrier: Maxis 3G network(Malaysia)

APN Name : net

User Name : Maxis

Password   : wap

 

Thanks