views:

284

answers:

3

How do I ping a server in J2ME / BlackBerry using java? This seems basic, but I can't find it in the javadocs. Thanks.

+4  A: 

Ping requires sending a ICMP packet to the host and unfortunately, J2ME and BlackBerry APIs do not give that low-level control over networking. The most you can do is establish HTTP or socket connections to an endpoint.

Marc Novakowski
Understood. What do you think the best way is to determine if I have internet connectivity via Java?
DanG
You could check the radio status using BlackBerry APIs, such as RadioInfo but if you want to check for the complete end-to-end you'll need to make an actual connection. You could either have a test page on your webserver with no content (blank HTML page) or have the client do an HTTP HEAD request so that the server only sends back HTTP headers.
Marc Novakowski
+2  A: 

If your goal is to determine whether or not you have Internet connectivity, the solution is a lot more complicated than an equivalent of sending a ping. The BlackBerry is not a normal IP-connected host like your average PC, and thus has many different underlying transports that can be used for connecting to something over the internet. These include:

  • WAP 1.0 (legacy transport, HTTP'ish only)
  • WAP 2.0 (carrier proxy, HTTP usually, Socket sometimes)
  • MDS (Proxy through BES infrastructure)
  • BIS-B (Proxy through RIM infrastructure, only available to BB alliance partners)
  • Direct TCP (Almost direct to the Internet, may require carrier APN configured on device)
  • Wi-Fi (Straight to the Internet)

So often the problem of reliably opening a connection can involve actually attempting some subset of the above transports, and it can be complicated to determine the availability and coverage of the above.

If you are using BB OS 5.0, then the problem is made much simpler through the newly introduced ConnectionFactory API. If you are using older BB OS versions, RIM has the sample code for a Network Diagnostic Tool available to help you out. Its not perfect, and you definitely need to do serious on-device testing to work out the kinks, but its a good starting point for learning the nitty-gritty of the necessary APIs.

octo
Alas, I was hoping for a simple solution.
DanG
A: 

What would it take to have RIM open access to ICMP on their stack. Clearly they have the protocol in their J2ME stack. Is it a question of app developers lobbying them. I know they are not oepn source like Android for example but don't they want to encourage app development?

SGM
It would be great but I personally think this is highly unlikely.
DanG