首页 » 黑莓开发 » 黑莓建立网络连接的不同方法

黑莓建立网络连接的不同方法

8949 1

1.MDS。
BES用MDS的方式进行连接,BES服务器和黑莓之间的数据传送通过AES或者DES的加密方式进行加密:
(HttpConnection) Connector.open
("http://www.tiandiyoyo.com");

为了能确认黑莓是用MDS的方式进行网络连接,我们可以指定它的参数deviceside=false,代码如下:
(HttpConnection)Connector.open
("http://www.tiandiyoyo.com;deviceside=false");

2.BIS。
这种的连接方式由于受到RIM限制,仅仅只有在某些合作伙伴制作的软件中才能使用,本文略。
3.TCP直连方式。
blackberry 3.8操作系统以后,开始支持这种新的连接方式,通过TCP直连,用户不需要再另外配置BES。
如果使用TCP直连方式,那么在option选项中的tcp设置中,用户必须预先指定APN。另外deviceside的参数则要设置成true,代码如下:
(HttpConnection)Connector.open
("http://www.tiandiyoyo.com;deviceside=true");

4.Wi-Fi连接。
黑莓手机可以通过WIFI建立其VPN连接到BES或者BIS,同样也可以不经过VPN而直接与目标机器连接。通过给添加参数interface=wifi来指定应用程序使用WIFI连接。代码如下:
(HttpConnection)Connector.open
("http://www.tiandiyoyo.com;interface=wifi");

5.WAP1.x
这是WAP连接,由运营商自己提供,注意的是,并不是每一个运营商都有提供这个服务。如果想指定用WAP1.X进行连接,则用如下代码:
(HttpConnection)Connector.open
(“http://wap.tiandiyoyo.com;WAPGatewayIP=127.0.0.1;WAPGatewayAPN=”);
上文所述两个参数WAPGatewayIP和WAPGatewayAPN是连接时必须要指定的,其他还有参数如下:
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.

6.WAP 2.0
4.2操作系统以后,黑莓开始支持WAP 2.0的连接方式,你可以通过servicebook来查看是否有这项服务。因此判断服务是否存在是使用WAP2.0的关键。应用程序通过获得servicebook中该服务条目的UID来进行网络连接。代码如下:
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 + ";ConnectionUID=" + uid); } else { //Consider another transport or alternative action. }

文章评分1次,平均分5.0

本文原始地址:https://www.tiandiyoyo.com/2011/10/differentwaytoconnect/
本站所有文章,除了特别注明外,均为本站原创,转载请注明出处来自www.tiandiyoyo.com

您可能还会对以下文章感兴趣:

评论前先开启评论开关:


1 Comment

载入分页评论...