Network connections

The BlackBerry® Application Platform offers two APIs that you can use to create network connections manually: the Network API and the GCF. Applications that target BlackBerry® devices that run BlackBerry® Device Software 5.0 and later can use the Network API. The Network API provides a simple interface for working with network transports, and setting a wide variety of parameters for a connection. You can use the GCF to create network connections on devices that run previous versions of the BlackBerry Device Software. However, using the GCF requires knowledge of more BlackBerry® APIs to discover what transports are available and how to configure them.

Regardless of which API you choose, the process of creating a network connection is similar. First, you open a network connection, then read and write data over that connection, and finally close the connection. Before you open a connection, you usually specify a transport, a protocol, and an end point. You can connect to network resources using a wide range of protocols. However, you should be aware that not all transports support all protocols. For example, WAP 1.0 and 1.1 only support HTTP over WAP and HTTPS over WAP or WTLS. The BlackBerry Application Platform supports the following protocols:

  • HTTP
  • HTTPS
  • Socket
  • TLS
  • SSL
  • UDP (Datagram)

The protocol and the end point are determined by your application, but the transport is determined by your users' operating environment. You may need to try more than one transport before you can make a successful connection. The following table suggests preference orders for consumer and enterprise applications that target users on CDMA and GPRS wireless networks.

CDMA

GPRS

Consumer

  1. TCP Wi-Fi®
  2. TCP Cellular
  3. BlackBerry® Internet Service
  4. WAP 2.0
  5. BlackBerry® Mobile Data System
  1. TCP Wi-Fi®
  2. BlackBerry® Internet Service
  3. WAP 2.0
  4. BlackBerry® Mobile Data System
  5. TCP Cellular

Enterprise

  1. BlackBerry MDS
  2. TCP Wi-Fi
  3. TCP Cellular
  4. BlackBerry Internet Service
  5. WAP 2.0
  1. BlackBerry MDS
  2. TCP Wi-Fi
  3. BlackBerry Internet Service
  4. WAP 2.0
  5. TCP Cellular

After you open a connection, you receive a Connection object that represents your connection. The javax.microedition.io package contains several interfaces that you can use to manipulate a Connection object.

Interface

Description

HttpConnection

This interface provides methods to set the HTTP request method (GET, POST, and so on) and headers, and send and receive data over the connection.

HttpsConnection

This interface includes all of the methods in the HttpConnection interface, and adds getSecurityInfo() that returns the certificate that is supplied by the web server.

SocketConnection

This interface exposes methods to send data to and receive data from a network host over a socket connection.

SecureConnection

This interface provides methods to create TLS and SSL socket connections. This interface includes all of the methods in the SocketConnection interface, and adds getSecurityInfo() that returns security information about the connection.

UDPDatagramConnection

This interface provides methods to retrieve information about the connection, and create new datagram objects.

InputConnection, OutputConnection

These interfaces provide access to a connection's input and output data streams.

When you are ready to use your connection, cast the Connection object according to the protocol that you used to open the connection. You will need the InputConnection and OutputConnection interfaces from the javax.microedition.io package to access the Connection object's send and receive functions. Those interfaces expose the Connection object's input and output streams. For more information about sending data over the connection, see the InputStream and OutputStream classes in the API reference for the BlackBerry® Java® SDK.


Was this information helpful? Send us your comments.