The BlackBerry was built to communicate.Sending and receiving email, browsing the Web, and often even downloading applications to your device require access to the wireless data network. Naturally, a lot of the most compelling BlackBerry applications also heavily feature networking as a core part of their functionalities. Fortunately, the BlackBerry JDE makes networking a snap. It offers a range of choices for getting your application to communicate with servers and other systems on the Internet or on a corporate network.
For the most part, you don’t have to worry about different device or wireless network characteristics; the BlackBerry platform abstracts that detail so you can concentrate on application-specific details. In this, we’ll discuss the BlackBerry data networking functionality, the different methods that a BlackBerry can use to connect, and when and how you might want to use them. We’ll then develop a couple of applications to explore making HTTP and TCP socket connections to interact with a web application on the internet.
The BlackBerry offers a number of different methods of making network connections. These include the BlackBerry Enterprise Server / BlackBerry Mobile Data System (BES/MDS), direct Transmission Control Procotol / Internet Protocol (TCP/IP), BlackBerry Internet Service (BIS), WiFi, Wireless Access Protocol (WAP) 1.0, and WAP 2.0. They each have certain advantages and disadvantages, and depending on the configuration of your device and environment, some of the methods might not be available. Generally, you can make all supported types of network connections: HTTP connections and TCP and UDP sockets over any of these connection methods. We’ll briefly cover the different connection methods.
Some of the different ways a BlackBerry device can make wireless connections
The BES allows BlackBerry devices to make network connections securely to servers inside a corporate network. This is accomplished through the MDS component of the BES, so connections made this way are sometimes referred to as BES/MDS connections. Connections made by the BlackBerry device using the MDS are actually proxied by the MDS; that is, the MDS makes connections on behalf of the BlackBerry device, and data is transferred to and from the device over the same secure channel that corporate BlackBerry email uses. Obviously, the BES/MDS connection method is available only to devices that have been activated on a BES. The advantage to using the BES/MDS is that because the MDS makes connections, it can resolve any servers that can be reached from the server
The BES allows BlackBerry devices to make network connections securely to servers inside a corporate network. This is accomplished through the MDS component of the BES, so connections made this way are sometimes referred to as BES/MDS connections. Connections made by the BlackBerry device using the MDS are actually proxied by the MDS; that is, the MDS makes connections on behalf of the BlackBerry device, and data is transferred to and from the device over the same secure channel that corporate BlackBerry email uses.
Obviously, the BES/MDS connection method is available only to devices that have been activated on a BES. The advantage to using the BES/MDS is that because the MDS makes connections, it can resolve any servers that can be reached from the server running the BES, meaning the servers behind the corporate firewall are reachable. The disadvantage is that if there are any restrictions on connections going from the BES to servers outside the network, those restrictions affect BlackBerry connections made through the BES, too. Note that by default, the browser on devices attached to a BES uses the MDS to make connections, meaning you can use the browser to access internal web servers. In fact, this is a good way to tell if your device uses the MDS to make connections; if the title of your browser application is called “BlackBerry Browser,” then your device uses the MDS tomake connections.
Just like most other smart phones, BlackBerry devices can also make direct TCP/IP connections using the wireless carrier’s infrastructure without going through any BlackBerry-specific service. This method works with most devices, although it can be disabled by a BES administrator for devices connected to a BES. The advantages are that this method is available on almost all BlackBerry devices. Occasionally, configuration problems with the Access Point Name (APN) used in direct TCP/IP connections (see the note) that can cause problems with TCP/IP connections. Also, though it’s becoming rarer, some BlackBerry wireless plans don’t include direct TCP/IP access.
NOTE: The BlackBerry device uses the )APN to make direct TCP/IP connections.The APN varies from carrier to carrier, and usually it is preconfigured on the device by the carrier; however, in some cases the configuration might have been lost. You can access APN configuration from the device Options by selecting Advanced Options ➤ TCP/IP. Some carriers require a username and password along with the APN. A search on the internet will usually provide a list of settings for the major wireless carriers. You can also specify the APN, username, and password if necessary when making your connection.This is tricky to manage with so many configurations and is outside the scope of this; for more information, see the BlackBerry JavaDocs for
BIS provides much of the same functionality for individual BlackBerry users as the BES does for corporate users, without the same level of security. If you use a BlackBerry device that’s not connected to a BES, you’re already using the BIS to send and receive your email.The BIS is also able to proxy connections in the same way as the BES/MDS does. Because the BIS can access servers only on the internet, it doesn’t give the access to a corporate network that using the BES/MDS does.
The main advantage to using a BIS connection over a direct TCP/IP connection is that some BlackBerry wireless plans don’t include direct TCP/IP access, but almost all include BIS access asit’s required for non-BES email. To enable your application to make connections through the BIS, you must be part of the BlackBerry Alliance Program and receive approval for your application to use the BIS. For that reason, we won’t cover BIS connections in this , but the basic mechanism is similar to the other connection types.
Many BlackBerry devices include WiFi networking (802.11 B/G and sometimes A). This allows your device to connect to a network via a WiFi router. You generally must set up access for specific WiFi routers. This is up to the device user, not the application developer. Assuming the device has been connected to a WiFi router, however, your application can make network connections over WiFi. The advantages are better speed, lower latency, and the fact that no carrier data charges are incurred.
The disadvantage is that WiFi coverage is not as widespread as wireless network coverage for most users, so you should support at least one other connection method. In the case of applications using a BES/MDS or BIS connection, the device can be configured to automatically use an appropriate WiFi hotspot where available to connect to the BES or BIS. This requires no additional effort on the part of the application; it’s handled automatically by the BlackBerry platform. You can, however, also make a direct WiFi connection explicitly from the application.
WAP 2.0 connects through the wireless carrier’s WAP gateway. Similar to direct TCP/IP connections, WAP 2.0 doesn’t use any BlackBerry specific infrastructure. The wireless plan associated with the BlackBerry device must also support WAP 2.0 access. Fortunately, this is the case with almost all devices sold. The big advantage of WAP 2.0 over direct TCP/IP is that no APN configuration is necessary, meaning that devices are more likely to be able to connect without needing any additional configuration
Unlike all the other connection methods mentioned, WAP 1.0 doesn’t support the full range of connection types. Specifically, security is limited. Though WAP 1.0 is supported by all BlackBerry devices, its limitations mean that unless you have a specific reason, you should use the other connection methods instead.
By default the BlackBerry uses the BES/MDS as the connection method for devicesactivated on a BES, and it uses the TCP/IP connection method for other devices. For devices activated on a BES, this is reasonable behavior because the BES connection is at least as secure as a direct TCP/IP connection. For devices not activated on a BES, a good method is to attempt to use WAP 2.0 first because a given device is more likely to be configured to use WAP 2.0 correctly and fallback to direct TCP/IP if necessary. We’ll cover how to do that later in this chapter.If you’re using BES/MDS, you can rely on the automatic WiFi fallback behavior. If you’re using direct TCP/IP, you might want to provide some WiFi functionality, depending on how heavily your application uses the network.