What Is - Network API alternative for legacy OS

by Retired ‎10-18-2010 03:17 PM - edited ‎03-14-2011 05:11 PM (34,747 Views)

 

The Network API was first introduced in BlackBerry® Device Software 5.0 to make network connectivity a breeze for developers. The primary goal of the Network API was to serve two basic use cases:

  1. Detect what transports are available.
  2. Create a connection over one of the available transports.

However, there are a lot of users who may not be running BlackBerry Device Software 5.0 and hence applications are unable to leverage the Network API in those cases. Keeping this in mind, I decided to put together an alternative API with source that developers can use out-of-the-box or extend as they see appropriate in BlackBerry Device Software earlier than 5.0. This open API consists of two simple classes.

 

TransportDetective: Allows an application to quickly detect what transports are available.

URLFactory: Appends proper parameters to a given URL to connect over a specific transport.

 

To demonstrate how easy it is to use these classes, here is a snippet that creates a connection over WAP2.

 

 

 

 

 

 

 

TransportDetective td = new TransportDetective();
boolean isWap2Available = td.isCoverageAvailable(TransportDetective.TRANSPORT_WAP2);
if(isWap2Available){
URLFactory urlFactory = new URLFactory("http://www.blackberry.com"); String connectionURL = URLFactory.getHttpWap2Url(td.getSrWap2); try{ HttpConnection connection = (HttpConnection)Connector.open(connectionURL); ... } catch(IOException){ // handle connection exception... } }

 

Similarly, you can use other transports such as TCP WiFi, TCP Cellular, MDS, BIS and WAP. Both socket and HTTP based connection URLs are supported including secured protocols such as SSL, TLS and HTTPS.

 

You may also be familiar with the Network Diagnostic Tool which can be used to quickly test specific transports with a given URL. It is worth mentioning that the latest version of the Network Diagnostic Tool is based on Transport Detective and URLFactory. The source code of this tool is also open. You can download this tool as well as the open Network API today using the links at the end of this article.

 

Related resources

Tutorial

Network Transports

 

Videos

Network Transports

Networking Transports II