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
Posts: 108
Registered: ‎08-05-2008
My Device: Not Specified
Accepted Solution

Can't hit an IP address

Hello, i am complete noob to both BlackBerry and Java.  Wrote my first app today. I am trying to send some info to an internal IP address (internal to the corporation).  It works from the simulator, but from the actual BlackBerry it says "Timed out". I know that the BlackBerry sees our network, since I can hit it from the built-in browser.  Maybe there is something more I need to do other than just hit an IP address?

 

Here is my code.

 

 

        private void SendToDevice(String IpAddress, String message)
        {
            String sendString = (char) 27 + "%-12345X@PJL RDYMSG DISPLAY = \""

                                                + message + "\"\r\n" + (char)27 + "%-12345X\r\n";

 

            String name = "socket://" + IpAddress + ":" + "9100" + ";deviceside=true";
           
            try
            {
                SocketConnection sc = (SocketConnection) Connector.open(name, Connector.READ_WRITE, true);
                InputStream is = sc.openInputStream();
                OutputStream os = sc.openOutputStream();
                os.write(sendString.getBytes());
                os.flush();
               
                Dialog.alert("Message sent");
            }
            catch (Exception ex)
            {
                Dialog.alert(ex.getMessage());
            }
        }

 

 

Thanks.

Developer
Posts: 205
Registered: ‎07-14-2008
My Device: 7230, 8700, 8820, 9000

Re: Can't hit an IP address

Sounds like a port problem to me.  Are you able to connect to that port from another computer outside of your network?

 

Earl 

Earl Oliver
Developer
Posts: 108
Registered: ‎08-05-2008
My Device: Not Specified

Re: Can't hit an IP address

Yes, the connection works perfectly fine from other computers and it works fine from the simulator.  Just does not work from the actual blackberry.

 

Regards

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

Re: Can't hit an IP address

From what you are saying, I suspect you run a BES connected BlackBerry.  Let us know if that is not the case. 

 

Your connection string is suffixed with ";deviceside=true", which tells the BlackBerry to use the external network, (i.e. direct TCP), via the wireless carrier.  For this to work, the IpAddress would need to be visible to the internet, which means I would be able to see that IP address from my computer.  However you say that the IP address is internal, so your device will never be able to connect to it, in the same way as if I opened a socket on my computer here, I would not be able to connect to it.  You need to use ";deviceside=false", which will route your socket via the BES/MDS - which is the way the Browser gets to your IP address.  Actually, if you don't specify a deviceside parameter at all, it will also probably work. 

 

Ahh I hear you say, but why does the simulator work?  Like the real device, it can connect via an MDS or connect directly.  To simulate connection via MDS, you need to bring up the MDS simulator - the connection should hang/timeout unless the MDS Simulator is active.  I'm think that your connection from your simulator works without the MDS simulator. 

 

I suspect the above is still not clear (sorry), but don't worry, you aren't the first to be confused by this.  I suggest you review the following:

 

Network Transports video:

http://na.blackberry.com/eng/developers/resources/videolibrary.jsp#tab_ddetail_subtab_jde

 

What Is - Different ways to make an HTTP or socket connection
DB-00396
http://tinyurl.com/3ynfr5

or

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

(Note that as of today (August 5, 2008), this article only mentions 3 of the methods, the video explains more including WiFi, BIS-B and Serial Bypass)

 

Managing Wireless Data Transport on BlackBerry 4 - Part 1

http://www.blackberry.com/knowledgecenterpublic/livelink.exe?func=ll&objId=832210&objAction=browse&s...

 

 

Note that there is a related discussion, with some additional points, on the following thread:

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=409

 

Developer
Posts: 108
Registered: ‎08-05-2008
My Device: Not Specified

Re: Can't hit an IP address

Peter,

 

You are the man.  It worked.

Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: Can't hit an IP address

Hi Peter,

 

I went through the link provided below followed the direction.

Still don't understand why my app is not getting the http connection.

 

URL to be connected:  

public static String main_url_post = "http://65.98.94.68/mobile/myconcierge/controller.php;deviceside=true";

 

- I was able to download my app from my server.

- I gave physical IP address.

- Using Direct TCP

- This app is working on Simulator but not on real device.

- Did code signing.

 

Do I need any setup on device?

Please help me.

 

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

Re: Can't hit an IP address

This is only my understanding of how this works, picked up from all over.  However I've not attended any classes or been to any RIM events where this is discussed, so I could be completely wrong in the following description.  Also this knowledge has been picked up in the UK, where we only have GPRS networks, no CDMA.  But you might find it useful and, it might be mostly right!  Fingers crossed.  

 

You have specified deviceside=true, so you are using the TCP stack on the device to get to your IP address.  This is being routed over your carrier's network, but needs to bridge from there to the real Internet - this is the APN (Access Point Node).  So you need to tell the BlackBerry connection how to find (and potentially log on to) the APN so that it can communicate outside the carrier's network. 

 

This APN is specific to the carrier, so to find out what to code, you will need to know what the carrier is, and then find out for that specific carrier the associated name, a Username to log in with and the password to use.  For example, for Vodafone in the UK the values are:

APN: internet

Username: web

Password: web

Note that some carriers don't bother with Username and password. 

 

Once you have these details, you can code them in two places - either as part of your URL (which means you can include them with your application so the user has to do nothing, but you need to know which carrier the user is using), or you can code them in the BlackBerry Options:

Options-->Advanced Options-->TCP

 

At this time, for your testing, you should code them in the Options.  Once you do that, your connection should work.

 

I suggest, with this extra knowledge, you review the following again.

What Is - Different ways to make an HTTP or socket connection
DB-00396
http://tinyurl.com/3ynfr5

 

Your app is working on the simulator because it does not need APN settings to get to the real internet, it is already on it.

 

if you still don't get it working, can you tell us exactly how it is failing.  What exception do you see?  If you see a security exception, you might try resetting your firewall.  To reset your Firewall:

Options-->Security-->Firewall, then use the Menu to Reset Settings.

Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: Can't hit an IP address

Hi Peter,

 

Thanks for your detail information.

I'm using T-Mobile USA. I got APN name from rim,  customer support said T-Mobile is using wap.voicestream.com.

 

However, when I call my server from the application I'm getting 500 Internal error if I use deviceside=true but if I use deviceside=false application gives error message imediately.

 

Do I need to setup anything else more?

 

Thanks,

DK. 

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

Re: Can't hit an IP address

The APN setting you have looks right for t-mobile USA.  You can generally find these details using Google.  In theory, I think the carrier should publish them too, but from experience, they are not that easy to find on carrier web sites.

 

The 500 HTTP return code is good news, that means you are getting through to your server site.  Obviously it is having a problem dealing with your request.  In theory, there should be some information in the logs etc. on your Server that explains what the problem is.  You could look for that. 

 

Does this URL work from a simulator?  You can use deviceside=true direct from a Sim and it should give you the same results.  This makes debugging much easier.

 

However I note that in the supplied URL above you are running php script.  Until you have the networking code sorted out, I would try to pick up a normal .htm page. 

 

Also you might try typing your URL into the Browser to see what happen there.

 

Since you are now dealing with problems on the Server end rather than the BlackBerry end, you have probably exhausted my useful input.  Also since you are now hitting the IP address, perhaps it is time to start another thread, if you have other problems.  However, I suggest an HTTP 500 from a php script is not an appropriate problem for this forum!

Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: Can't hit an IP address

I'll see the server log.

 

Yes, the URL can be accessed from simulator using deviceside=true but without this option I can not reach.

From the browser it is working fine.

 I just looked server log and although I'm getting HTTP 500 error, server doesn't have this error log means that application is not accessing the page.

 

 

Thanks,

DK