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
New Developer
Posts: 6
Registered: ‎11-11-2008
My Device: Not Specified

Socket Connection Problem

Although there are different positng I cannot get my java program to run! My BB 8800 is setup with an BES. Our intranet is blocking socket connections on the port 2001 (the one I am trying). Hence I am trying to use direct TCP.

 

I am using the socket.java from the samples (just removed the receiving part), set up my TCP APN (T-mobile Germany: internet.t-mobile, user: t-mobile, password: tm) in my BB and have the following code:

...

          _screen.updateDisplay("Opening Connection...");
            String url = "socket://" + _screen.getHostFieldText() + ":2001" + (_screen.isDirectTCP() ? ";apn=internet.t-mobile;TunnelAuthUsername=t-mobile;TunnelAuthPassword=tm;deviceside=true;" : "");                                   
            _screen.updateDisplay("Connect to "+url);
            connection = (StreamConnection)Connector.open(url);
            _screen.updateDisplay("Connection open");
          
            //_in = new InputStreamReader(connection.openInputStream());
            _out = new OutputStreamWriter(connection.openOutputStream());           
            _screen.updateDisplay("Send string");
            // Send the HELLO string.
            exchange("Hello");

 ...

The host is an IP address. I tried direct TCP socket communication (checkbox marked in UI) as well indirect.

1) not direct: communication established, characters send (assumed by BB) but nothing arrives at the server!

2) direct: socketdemo hangs while trying to connect

 

The server side is a simple, multithreaded socket listener, which works fine (tested).

...

       Socket clientSocket = null;

 

try {
                System.out.println("SimpleSocketServer.WaitingForClient");
                clientSocket = serverSocket.accept(); //blocking call - waits for a connection
                System.out.println("SimpleSocketServer.ClientConnecting" + ":" + clientSocket.getInetAddress().getHostAddress());
            } catch (IOException e) {
                System.err.println(e);
                System.exit(-1);
            }

 

...

 

Could someone please help me? I tried nearly everthing.


Regards

R

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

Re: Socket Connection Problem

Is your URL mising ";deviceside=true"?

 

I presujme, since you are using direct TCP, that the IP Address you are using is externally addressable - in other words, if I knew your URL, I could connect - is this true?

New Developer
Posts: 6
Registered: ‎11-11-2008
My Device: Not Specified

Re: Socket Connection Problem

Yes my url contains "deviceside=true":

String url = "socket://" + _screen.getHostFieldText() + ":2001" + (_screen.isDirectTCP() ? ";apn=internet.t-mobile;TunnelAuthUsername=t-mobile;TunnelAuthPassword=tm;deviceside=true;" : "");     

 
My server is also accessible from other, standard PCs or devices. But I am trying to use the IP address instead of the name, which in my opinion should work as well.
 
Regards
Reinhard
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Socket Connection Problem

Apologies, I expect to see deviceside=true at the start of the connection string so missed it...

 

I think using IP Address is fine, I do that with socket connections. 

 

I've done a quick look round for the APN settngs for tMobile in Germany, and I get a varierty of different settings.  How have you determined the ones that you use?

New Developer
Posts: 6
Registered: ‎11-11-2008
My Device: Not Specified

Re: Socket Connection Problem

I also tried different settings for T-Mobile. The one that I am currently using (internet.t-mobile, t-mobile, tm) are successfully tested with a different GPS/GPRS device.

 

Actually I am wondering about the facts, that

1- there is no error message when using not direct TCP, but the socketdemo assumes that everything is successfully sent.

2- there is not timeout but the program just hangs if there is direct TCP

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

Re: Socket Connection Problem

I agree, those are both odd.  I would have expected a timeout at least for the direct TCP.  What OS level do you have in your 8800?  Do you have any other devices you can test on?

 

DO you have this available as a OTA download, if so perhaps I would try it?

New Developer
Posts: 6
Registered: ‎11-11-2008
My Device: Not Specified

Re: Socket Connection Problem

Blackberry 8800

V4.2.1.120 (Platform 2.3.0.80)

 

Unfortunately I do not have the option to provide the program via OTA. I could send it via email.... Do you want to see the source? 

 


      

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

Re: Socket Connection Problem

I have an 8800, 4.2.1.68, 2.3.0.54 I can stick it on here. 

 

On reflection, that was a silly idea to suggest I could run your code directly - you have tMobile Germany settings and I'm on Vodafone UK!  So I will probably need the source so I can change it, unless you want to hard code the Voda settings

";apn=internet;tunnelauthusername=web;tunnelauthpassword=web"

Alternatively, you can just remove the apn settings completely, then I can code what I need in the TCP Options on the device.

Highlighted
New Developer
Posts: 6
Registered: ‎11-11-2008
My Device: Not Specified

Re: Socket Connection Problem

Actually I enhanced the exception handling (formerly only  System.err.println(e.toString()); - showing nothing) and the openConnection url by mode and timeout parameter

connection = (StreamConnection)Connector.open(url, Connector.READ_WRITE, timeouts);

 

Now I am getting at least an exception message: "Unable to open connection" in direct  TCP mode when showing


        catch(IOException e)
        {
            _screen.updateDisplay("IOException: " + e.getMessage());             
            e.printStackTrace();
            System.err.println(e.toString());
        }

 

But still I have no clue why the connection is not possible.

New Developer
Posts: 6
Registered: ‎11-11-2008
My Device: Not Specified

Re: Socket Connection Problem

PROBLEM Solved.

 

tried it on port 80 and it worked, hence checked the firewall, which was enabled! After disabling it (/etc/config.d/iptables disable) it worked well.

 

thx for support and ideas!