This article focuses on five methods for connecting to HTTP or Socket through BlackBerry development. In BlackBerry development, network-related settings are sometimes confusing, the following is an article on network configuration programming. Please refer to this article for details.
Five methods for BlackBerry development to connect to HTTP or Socket
BlackBerry APIs provide five methods for HTTP or socket connection, including:
1. blackberrypoliciseserver (BES) Mode
This method uses BES's BlackBerryMDSServices for network connection. BlackBerryMDSServices is responsible for processing all browser requests or connection requests and Data Encryption. This is the default connection method of blackberry, as follows:
Example 1: (HttpConnection) Connector. open ("http://www.testserver.com ");
The above code automatically uses BlackBerryMDSServices as its default connection path. In actual development, to ensure that the application uses usesBlackBerryMDSServices as its connection path, we need to add the parameter "deviceside = false" at the end of the URL, which is also recommended as follows:
Example 2: (HttpConnection) Connector. open ("http://www.testserver.com; deviceside = false ");
2. BlackBerryInternetServie Mode
This method is a connection interface provided by a third party. It does not encrypt data. You can use HTTPS and SSL for secure connections. Note: currently only open to third-party open partners who have joined BlackBerryAllianceProgram, For details, refer to: http://na.blackberry.com/eng/partners/alliance.jsp
3. DirectTCP
This method allows direct TCP connection on a blackberry that does not use BlackBerryMDS. To enable directTCP, you need to set the APN and the corresponding user name and password in "options-advanced options-TCP/IP" on the mobile phone.
Note 1: Blackberry phones running on the iDEN network include 6510, 7510, 7520, and 7100i. If the deviceside parameter is not specified, for example, 1), the default connection is directTCP; if the deviceside parameter is not specified for other Blackberry phones running on the iDEN network, the default connection is BlackBerryMDS.
NOTE 2: If BlackBerryMDS does not exist during connection, the BlackBerry will automatically adopt the directTCP method.
Therefore, if you want to use directTCP as the default connection method of the BlackBerry phone, we recommend that you add the "deviceside = true" parameter to the URL, as shown below:
Example 3: (StreamConnection) Connector. open ("socket: // testserver: 600; deviceside = true ");
4. Wi-Fi
If you need to create a network connection on Wi-Fi, you do not need to consider the special underlying logic in the application, you can add the parameter "interface = wifi" to the URL to achieve wi-fi connection, as shown below:
Example 4: (StreamConnection) Connector. open ("socket: // testserver: 600; interface = wifi ");
5, WAP1.x
Not all mobile operators support connections through the WAP Gateway. To create a WAP connection, the developer must contact the mobile operator, obtain whether such support is provided and their WAP network management parameters.
The following is an example of an HTTP Connection Based on the WAP Gateway:
Example 5: (HttpConnection) Connector. open ("http://wap.google.com; WAPGatewayIP = 127.0.0.1; WAPGatewayAPN = carrier.com. gprs ");
Note: The two parameters WAPGatewayIP and WAPGatewayAPN must be specified and are separated by ";". The following lists all WAP parameters, during actual development, determine which parameters need to be set based on the information provided by the carrier.
6. WAP2.0
If you want to connect to the gateway of WAP2.0, you must specify servicerecord and UID during connection. The following code illustrates how WAP2.0 works during connection:
Example 5:
- ServiceBookServiceBooksb=ServiceBook.getSB();
- ServiceRecord[]records=sb.findRecordsByCid("WPTCP");
- Stringuid=null;
-
- for(inti=0;i<records.length;i++)
- {
- //Searchthroughallservicerecordstofindthe
- //validnon-Wi-Fiandnon-MMS
- //WAP2.0GatewayServiceRecord.
- 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)
- {
-
- //openaWAP2connection
- Connector.open(_url+";ConnectionUID="+uid);
- }
- else
- {
- //Consideranothertransportoralternativeaction.
- }
-
Common User problems:
1. Why is it okay for apps Based on WAP connection to test on mobile phones that do not activate BES and cannot connect to mobile phones that activate BES?
A: The Connection Method in Example 1 is used for connection. The solution is to use the connection method in Example 5 in this article.
2. How do I connect to BES and BIS through Wi-Fi? Can I directly connect to another destination address?
A: Wi-Fi can be connected to BES and BIS through BBI, or you can configure a VPN on Wi-Fi to directly connect to BES. You can also bypass BBI, BES, And BIS to directly connect to other servers.