Connection Method: Using Direct TCP/IP Instead of BES/MDS BLACKBERRY

Now, let’s take a few minutes to see how to force a connection to make a direct TCP/IP connection to the server instead of using the BES/MDS. The Networking application currently uses the device’s default connection method. As mentioned earlier, if you run the application on a device that’s not activated on a BES, the requests will already go over direct TCP/IP. However,if you run on a device connected to a BES, the POST and GET requests are done through the BES. To force them to go directly, we just have to add a BlackBerry-specific parameter to the end of the URL when we call Connector.open. The parameter we want is ;deviceside=true,so the URL for the web application becomes:

Modify the run method of HttpRequestDispatcher to add this automatically.HttpConnection connection = (HttpConnection)Connector.open(url + ";deviceside=true"); We can actually test this on the simulator because it respects this parameter, too. If we specify deviceside=true, the simulator won’t connect through the MDS simulator. So, uncheck the appropriate Launch Mobile Data System check box, ensure the MDS command window isn’t open (if it is, just close it), and then run the application again. We’ll be able to make connections without the MDS simulator running!

Making a Connection Using WAP 2.0

I mentioned that WAP 2.0 was a better choice than direct TCP/IP because of configuration issues. It’s a little more difficult to use, as it requires an extra parameter at the end of the URL that includes the UID of the service record for the WAP 2.0 protocol. We’ll start by creating a method in HttpRequestDispatcher to find this service. The WAP 2.0 service book record has a CID of WPTCP, but this CID is used for a few other connection methods, so the recommended algorithm for finding the correct record is to look for a record with a CID of WPTCP and a UID that doesn’t contain WIFI or MMS. First, add the following imports to the top of the file to get access to the service bookrelated classes:

import net.rim.device.api.servicebook.ServiceBook;
import net.rim.device.api.servicebook.ServiceRecord;

The code for the method follows:

private ServiceRecord getWAP2ServiceRecord() {
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.getRecords();
for(int i = 0; i < records.length; i++) {
String cid = records[i].getCid().toLowerCase();
String uid = records[i].getUid().toLowerCase();
if (cid.indexOf("wptcp") != -1 &&
uid.indexOf("wifi") == -1 &&
uid.indexOf("mms") == -1) {
return records[i];
}
}
return null;
}

If a matching service record isn’t found, WAP 2.0 isn’t configured on the device, and the method will return null. In that case, default back to a direct TCP/IP connection. Otherwise, we’ll add the parameter ConnectionUID=<UID of the record> to indicate that we want to connect using WAP 2.0. Modify the code in the run method of HttpRequestDispatcher as follows:

ServiceRecord record = getWAP2ServiceRecord();
String connectionParameters = ";deviceside=true";
if(record != null){
connectionParameters += ";ConnectionUID=" + record.getUid();
}
HttpConnection connection = (HttpConnection)Connector.open(url + connectionParameters);

Making a Connection Using BIS

Applications are approved to use BIS to connect on a case-by case basis, but you have to be a member of the BlackBerry Alliance Program to get access.Generally, the BlackBerry Alliance Program is good to get involved with as an independent software vendor for BlackBerry.

More information about the Alliance Program is available: For those reasons, making a connection using BIS is outside the scope of thisbook,but if you understand the basics of connecting using BES/MDS and direct TCP/IP, you shouldn’t have any trouble connecting over BIS.

Making a WiFi Connection

Connecting via WiFi is easy if the device has been configured to use a WiFi access point. Remember, if your application is used on a device that’s activated on a BES, and you’re using the BES/MDS or default connection method, your connection is made over WiFi as per the device configuration. To explicitly force a direct WiFi connection, append the parameter ;interface=wifi to the end of the connection string. For example, modify the connector call to be:

HttpConnection connection = (HttpConnection)Connector.open(url + ";interface=wifi");

Note that this bypasses any other wireless network connection method, so if the device is not within range of an appropriate WiFi access point, the connection will fail.



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

BLACKBERRY Topics