Different ways to make an HTTP or socket connection

by Retired on ‎02-17-2010 12:27 PM - edited on ‎11-22-2010 07:28 PM by Anonymous (46,708 Views)

Summary

 

This article applies to the following:

  • BlackBerry® smartphones based on Java® technology

Procedure

 

The BlackBerry® Java® Development Environment (BlackBerry JDE) application programming interface (API) reference includes five ways to make a Hypertext Transfer Protocol (HTTP) or socket connection.

 

BlackBerry Enterprise Server using the BlackBerry MDS Connection Service

 

The BlackBerry MDS Services are included in the BlackBerry Enterprise Server software and handle all browser or connection requests and route the requests accordingly. Data flowing between the BlackBerry smartphone and BlackBerry Enterprise Server is encrypted with Advanced Encryption Standard (AES) or Triple Data Encryption Standard (Triple DES). A connection made through BlackBerry MDS provides seamless roaming across wireless service providers that support BlackBerry smartphone service.

 

By default, all BlackBerry smartphone models, except the BlackBerry® 6500 Series and the BlackBerry® 7500 Series, use BlackBerry MDS. The following is an example:

 

 

HttpConnection) Connector.open 
("http://www.testserver.com");

 

To make sure that an application uses BlackBerry MDS Services as its connection pathway on all BlackBerry smartphone models, append the deviceside=false parameter to the end of the URL. The following URL is an example:

 

 

(HttpConnection)Connector.open 
(“http://www.testserver.com;deviceside=false”);

BlackBerry Internet Service

 

Applications are also able to make connections through the BlackBerry Internet Service. This connection route is available to third-party developers and is subject to an application approval process. Data flowing over this connection is not encrypted. Hypertext Transfer Protocol over Secure Sockets Layer (HTTPS) or Secure Sockets Layer (SSL) can be used to secure a connection. A BlackBerry Internet Service connection provides seamless roaming across wireless service providers that support BlackBerry smartphone service. Currently, this transport is only available to BlackBerry Alliance Program members, subject to approval. Information about the BlackBerry Alliance Program can be found at the following web site: http://na.blackberry.com/eng/partners/alliance.jsp

Direct TCP stack

 

For BlackBerry smartphones running BlackBerry® Device Software 3.8 and later, a direct TCP stack is included, which allows a direct TCP connection to be opened from the BlackBerry smartphone without using BlackBerry MDS.

 

For BlackBerry smartphones operating on the iDEN® network, including the BlackBerry® 6510 smartphone, BlackBerry® 7510 smartphone, BlackBerry® 7520 smartphone, and BlackBerry® 7100i smartphone, a direct TCP connection is used if the deviceside parameter is not present. BlackBerry smartphones not operating on the iDEN network use BlackBerry MDS as the default connection if the deviceside parameter is not specified.

 

If BlackBerry MDS is not available at the time of connection, the BlackBerry smartphone reverts to direct TCP.

 

For the BlackBerry smartphone to use direct TCP, the user name and password fields must be completed under Options > TCP or supplied by the application. this article explains how to specify access point name (APN) information in a direct TCP connection.

 

To override the default behaviour of the default connection on the BlackBerry smartphone, the deviceside parameter must be included within the connection statement. The following is an example:

 

 

(StreamConnection)Connector.open
("socket://testserver:600;deviceside=true");

Wi-Fi network

 

A Wi-Fi enabled BlackBerry smartphone is able to connect over a Wi-Fi network to the BlackBerry® Infrastructure. The BlackBerry Infrastructure exists between a BlackBerry smartphone and the BlackBerry Internet Service or BlackBerry Enterprise Server, allowing for connectivity to these components. A BlackBerry smartphone can also be configured to connect directly to a BlackBerry Enterprise Server using a virtual private network (VPN) connection over a Wi-Fi network. What this means is that applications that are making a connection through a BlackBerry Enterprise Server or BlackBerry Internet Service (options 1 and 2 ) can have their connections automatically routed through a Wi-Fi connection without any special logic required in the application. Applications can also make a connection over a Wi-Fi network directly to their destination server, bypassing the BlackBerry Infrastructure, BlackBerry Enterprise Server and BlackBerry Internet Service. To specify that a connection must be made over a Wi-Fi network, the interface=wifi parameter is used. The following is an example:

 

 

(StreamConnection)Connector.open
(“socket:// testserver:600;interface=wifi”);

Wireless service provider WAP 1.x gateway

 

The connection string uses WAP parameters, which are hosted by a wireless network provider. Not all wireless service providers support connections through their WAP gateway. Contact the wireless network service to find out if support exists and to obtain a listing of their WAP gateway parameters.

 

The following is an HTTP connection over a WAP gateway:

 

 

(HttpConnection)Connector.open
("http://wap.google.com;WAPGatewayIP=127.0.0.1;WAPGatewayAPN=carrier.com.gprs")

 

The WAPGatewayIP and WAPGatewayAPN values are required parameters. Each parameter specified must be separated by a semicolon. The following is a table of supported WAP parameters:

 

Parameter  Description 
WapGatewayIP IP address of the gateway.
WapGatewayAPN APN for General Packet Radio Service (GPRS) networks only. For testing purposes, you can use rim.net.gprs
WapGatewayPort Gateway port value. If port 9203 is specified, Wireless Transport Layer Security (WTLS) is used unless WapEnableWTLS=false is specified.
WapSourceIP IP address of the source.
WapSourcePort Source port value.
TunnelAuthUsername User name for APN session, when Password Authentication Protocol (PAP) or Challenge Handshake Application Protocol (CHAP) authentication is used.
TunnelAuthPassword Password for APN session, when PAP or CHAP authentication is used.
WapEnableWTLS Explicitly turns on or turns off WTLS. If this parameter is not specified, WTLS is used by default for connections to port 9203.


Wireless service provider WAP 2.0 gateway

 

BlackBerry Device Software 4.2.0 and later includes the ability to connect through a WAP 2.0 gateway. This is done by locating the service record on the BlackBerry for the WAP 2.0 gateway and using its UID when making the connection. The following code sample demonstrates how this can be done.

 

 

ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.findRecordsByCid("WPTCP");
String uid = null;

for(int i=0; i < records.length; i++)
{
//Search through all service records to find the
//valid non-Wi-Fi and non-MMS
//WAP 2.0 Gateway Service Record.
if (records[i].isValid() && !records[i].isDisabled())
{

if (records[i].getUid() != null && records[i].getUid().length() != 0)
{
if ((records[i].getUid().toLowerCase().indexOf("wifi") == -1) &&
(records[i].getUid().toLowerCase().indexOf("mms") == -1))
{
uid = records[i].getUid();
break;
}
}
}
}

if (uid != null)
{

//open a WAP 2 connection
Connector.open(_url + ";deviceside=true;ConnectionUID=" + uid);
}
else
{

//Consider another transport or alternative action.
}