分享
 
 
 

通用联接框架(GCF)连接类型使用总结

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

通用连接框架(Generic Connection Framework,GCF)是在J2ME平台中广泛使用的用于联网和IO处理的类。本文主要讲述GCF的关键特性,然后把各种连接的关键信息总结为列表的形式,供开发者在使用GCF的时候参考。

使用GCF建立连接的方式类似下面程序片断:

...

import java.lang.String;

import javax.microedition.io.*;

static Connection Connector.open( String name );

...

我们关注的主要是Connection和name参数,下面解释什么是name?什么是Connection。Name实际上是与Connection关联的URI。形式如:

scheme : [address] [params]

其中scheme是协议的名称,比如http;address是指定协议的连接端点;params是一些可选的参数,形式类似于language=Chinese。我们给出一个例子:http://www.j2medev.com/servlet?hello=world。

在介绍Connection之前,我们有必要说明一下MIDP规范中说明的一个问题,那就是设备支持什么协议。在MIDP规范中,协议支持的分类共三种:必须,推荐和可选。http和https是MIDP规范要求设备必须支持的,其他的协议都列入了推荐和可选类别中。在其他的可选包中通常也会用到GCF的扩展,比如WMA使用了MessageConnection,JSR75使用了FileConnection。我们可以通过查询系统属性的方式来检查设备是否支持相关的协议连接。比如,我们可能使用下面的方法查询设备对jsr75的支持情况:

...

import java.lang.System;

import java.lang.String;

String name = "microedition.io.file.FileConnection.version";

String value = System.getPRoperty( name );

Boolean hasFile;

if ( ( value != null ) && value.equals( "1.0" ) )

hasFile = true;

else

hasFile = false;

...

在使用GCF的时候,我们首先应该根据项目需求选择适当的Connection。关于Connection的层次结构可以从下图清晰的了解到,

点击查看大图

下面的部分总结了GCF支持的连接类型,这些信息按照接口、BNF语法和例子来分组,供开发者参考:

MIDP2.0(JSR 118)

串口连接

支持: 可选

接口: javax.microedition.io.CommConnection,扩展了StreamConnection

BNF:

url ::== "comm:" port_id *(option_list)

port_id ::== 1*(characters)

option_list ::== *(baudrate bitsperchar stopbits parity blocking

autocts autorts)

baudrate ::== ";baudrate=" digits

bitsperchar ::== ";bitsperchar=" bit_value

bit_value ::== "7" "8"

stopbits ::== ";stopbits=" stop_value

stop_value ::== "1" "2"

parity ::== ";parity=" parity_value

parity_value ::== "even" "odd" "none"

blocking ::== ";blocking=" on_off

autocts ::== ";autocts=" on_off

autorts ::== ";autorts=" on_off

on_off ::== "on" "off"

例子:

"comm:0;bitsperchar=8;stopbits=1;parity=none"

"IR1"

可以使用下面的方法列出port_id的值:

import java.lang.System;

import java.lang.String;

String ports = System.getProperty( "microedition.commports" );

--------------------------------------------------------------------------------

HTTP连接

支持: 必须

接口: javax.microedition.io.HttpConnection ,扩展了ContentConnection

定义: IETF RFC 1738, Section 3.3 HTTP

例子:

"http://java.sun.com"

"http://www.sun.com:80"

--------------------------------------------------------------------------------

HTTPS Connection

支持: 必须

接口: javax.microedition.io.HttpsConnection,扩展了HttpConnection

例子:

"https://java.sun.com"

"https://www.sun.com:443"

--------------------------------------------------------------------------------

安全连接

支持: 推荐

接口: javax.microedition.io.SecureConnection ,扩展了SocketConnection

BNF:

url ::== "ssl://" hostport

hostport ::== host ":" port

host ::== host name or ip address

port ::== numeric port number

例子:

"ssl://www.sun.com"

"ssl://java.sun.com:443"

注意: 只支持客户端模式,设备上不支持服务器模式

--------------------------------------------------------------------------------

Server Socket Connection

支持: 推荐

接口: javax.microedition.io.ServerSocketConnection ,扩展了StreamConnectionNotifier

BNF:

url ::== "socket://" "socket://" hostport

hostport ::== host ":" port

host ::== omitted for inbound connections

port ::== numeric port number (omitted for system assigned port)

例子:

"socket://:25"

"socket://:17"

"socket://"

--------------------------------------------------------------------------------

Socket Connection

支持: 推荐

接口: javax.microedition.io.SocketConnection ,扩展了StreamConnection

BNF:

url ::== "socket://" hostport

hostport ::== host ":" port

host ::== host name or IP address (omitted for inbound connections)

port ::== numeric port number

例子:

"socket://developer.sun.com/techtopics/mobility:80"

"socket://www.sun.com:53"

--------------------------------------------------------------------------------

Datagram Connection

支持: 推荐

接口: javax.microedition.io.UDPDatagram.Connection ,扩展了DatagramConnection

BNF:

url ::== "datagram://" "datagram://" hostport

hostport ::== host ":" port

host ::== host name or IP address (omitted for inbound connections)

port ::== numeric port number (omitted for system assigned port)

例子:

"datagram://" - server with system assigned port

"datagram://:7" - server with specified port

"datagram://java.sun.com:80" - client

JSR 75 PDA Optional Packages

查询方式: System.getProperty( "microedition.io.file.FileConnection.version" ).equals( "1.0" );

接口: javax.microedition.io.file.FileConnection ,扩展了StreamConnection

定义: IETF RFC 1738, Section 3.10 Files

例子:

"file:///CFCard/music/thewayup/opening.mp3"

"file:///RWM/photos/emma.jpg"

"file://localhost/RWM/photos/thekids.jpg"

JSR 82 Java APIs for Bluetooth Wireless Technology, version 1.0a

是否支持蓝牙只能通过尝试的方式得到了。

Serial Port Profile (SPP)

接口: javax.microedition.io.StreamConnection

接口: javax.microedition.io.StreamConnectionNotifier

BNF:

url ::== srvString cliString

srvString ::== "BTspp" ":" "//" srvHost 0*5(srvParams)

cliString ::== "btspp" ":" "//" cliHost 0*3(cliParams)

cliHost ::== btAddress ":" channel

srvHost ::== "localhost" ":" uuid

channel ::== %d1-30

uuid ::== 1*32(HEXDIG)

bool ::== "true" "false"

btAddress ::== 12*12(HEXDIG)

text ::== 1*( ALPHA DIGIT " " "-" "_" )

HEXDIG ::== "A".."F" "a".."f" "0".."9"

ALPHA ::== "A".."Z" "a".."z"

DIGIT ::== "0".."9"

name ::== ";name=" text

master ::== ";master=" bool

encrypt ::== ";encrypt=" bool

authorize ::== ";authorize=" bool

authenticate ::== ";authenticate=" bool

cliParams ::== master encrypt authenticate

srvParams ::== name master encrypt authorize authenticate

例子:

"btspp://000a95020c7b:5;name=SPPex"

"btspp://localhost:8CDF20D5A6B711D99042000A95BDA676;name=SPPex"

--------------------------------------------------------------------------------

Logical Link Control and Adaptation Profile (L2CAP)

接口: javax.bluetooth.L2CAPConnection ,扩展了Connection

接口: javax.bluetooth.L2CAPConnectionNotifier ,扩展了Connection

BNF:

url ::== srvString cliString

srvString ::== "btl2cap" ":" "//" srvHost 0*7(srvParams)

cliString ::== "btl2cap" ":" "//" cliHost 0*5(cliParams)

cliHost ::== address ":' psm

srvHost ::== "localhost" ":" uuid

psm ::== 4*4(HEXDIG)

receiveMTU ::== ";receiveMTU=" 1*(DIGIT)

transmitMTU ::== ";transmitMTU=" 1*(DIGIT)

cliParams ::== master encrypt authenticate receiveMTU transmitMTU

srvParams ::== name master encrypt authorize authenticate

receiveMTU transmitMTU

例子:

"btl2cap://000a95020c7b:5;name=sync l2cap"

"btl2cap://localhost:8CDF20D5A6B711D99042000A95BDA676;name=sync l2cap"

--------------------------------------------------------------------------------

Object Exchange Protocol (OBEX)

接口: javax.obex.sessionNotifier ,扩展了Connection

接口: javax.obex.ClientSession ,扩展了Connection

接口: javax.obex.Operation ,扩展了ContentConnection

BNF:

url ::== tcpObex irdaObex btObex

btObex ::== btSrvString btCliString

tcpObex ::== tcpSrvString tcpCliString

irdaObex ::== irdaSrvString irdaCliString

tcpCliString ::== "tcpobex" ":" "//" tcpHost

tcpSrvString ::== "tcpobex" ":" "//" 0*1(ipPort)

ipPort ::== 1*(DIGIT)

ipAddress ::== 3*3(%d0-255 ".") (%d0-255)

ipName ::== 1*( hostLabel "." ) topLabel

topLabel ::== ALPHA ALPHA *(alphaNum "-") alphaNum

hostLabel ::== alphaNum alphaNum *(alphaNum "-") alphaNum

tcpHost ::== ipName 0*1(":" ipPort) ipAddress 0*1(colon ipPort)

btSrvString ::== "btgoep" ":" "//" btSrvHost 0*5(btSrvParams)

btCliString ::== "btgoep" ":" "//" btCliHost 0*3(btCliParams)

btCliParams ::== master encrypt authenticate

btSrvParams ::== name master encrypt authorize authenticate

btCliHost ::== btAddress ":" channel

btSrvHost ::== "localhost" ":" uuid

irdaSrvString ::== "irdaobex" ":" "//" irdaSrvHost 0*1(irdaParams)

irdaCliString ::== "irdaobex" ":" "//" irdaCliHost 0*1(irdaParams)

irdaSrvHost ::== "localhost" 0*1("." 1*(DIGIT))

irdaCliHost ::== "discover" 0*1("." 1*(DIGIT))

"addr." 2*8(HEXDIG)

"conn"

"name." 1*(characters)

irdaParams ::== ";ias=" 1*(characters) 0*("," 1*(characters))

characters ::== %d0-255

alphaNum ::== ALPHA DIGIT

例子:

"tcpobex://litespeed:6512"

"tcpobex://:6512"

"btgoep://000a95020c7b:996"

"btgoep://localhost:8CDF20D5A6B711D99042000A95BDA676;name=playlist"

"irdaobex://discover.08;ias=fax"

"irdaobex://localhost.08;ias=fax,OBEX,OBEX:IrXfer"

JSR 120 Wireless Messaging API (WMA), version 1.1

查询方式: System.getProperty( "wireless.messaging.sms.smsc" ) != null

接口: javax.wireless.messaging.MessageConnection ,扩展了Connection

BNF:

url ::== "sms://" address_part

address_part ::== foreign_host_address local_host_address

local_host_address ::== port_number_part

port_number_part ::== ":" digits

foreign_host_address ::== msisdn msisdn port_number_part

msisdn ::== "+" digits digits

digits ::== DIGIT DIGIT digits

例子:

"sms://+19055551212"

"sms://+14165551212:5009"

"sms://:5009"

--------------------------------------------------------------------------------

GSM Cell Broadcast Adapter

接口: javax.wireless.messaging.MessageConnection ,扩展了Connection

BNF:

url ::== "cbs://" address_part

address_part ::== message_identifier_part

message_identifier_part ::== ":" digits

digits ::== DIGIT DIGIT digits

例子:

"cbs://:5009"

"cbs://:1089"

JSR 205 Wireless Messaging API (WMA), version 2.0

查询方式: System.getProperty( "wireless.messaging.mms.mmsc" ) != null

接口: javax.wireless.messaging.MessageConnection ,扩展了Connection

BNF:

url ::== "mms://" address_part

address_part ::== (e-mail-address device-address shortcode-address

application-id)

device-address ::== general-phone-address [application-id]

general-phone-address ::== (global-telephone-type "/TYPE=PLMN")

(ipv4 "/TYPE=IPv4")

(ipv6 "/TYPE=IPv6")

(escaped value "/TYPE=" address-type)

global-telephone-type ::== "+" *(DIGIT)

ipv6 ::== IETF RFC 1884

ipv4 ::== 1 *DIGIT "." 1*DIGIT "." 1*DIGIT "." 1*DIGIT

application-id ::== ":" [("com" "org" "edu" "gov")] [organization] [*(package-name)] class-name

organization ::== "." *applicationID-symbol

package-name ::== "." *applicationID-symbol

class-name ::== "." *applicationID-symbol

address-type ::== *address-char

address-char ::== *(ALPHA DIGIT "_")

e-mail-address ::== mailbox group

group ::== phrase "." [#mailbox] ";"

phrase ::== *(space Word space)

mailbox ::== addr-spec [phrase] route-addr

route-addr ::== "<" [route] addr-spec ">"

route ::== 1#("@" domain) ":"

addr-spec ::== local-part "@" domain

local-part ::== word *("." word)

domain ::== sub-domain *("." sub-domain)

sub-domain ::== domain-ref domain-literal

domain-ref ::== atom

domain-literal ::== "[" *(dtext quoted-pair) "]"

atom ::== ALPHA DIGIT "!" "#" "$" "%" "'" "*"

"+" "-" "=" "?" "{" "}" "" "~"

"^" "_"

word ::== atom quoted-string

quoted-string ::== '"' (qtext qpair) *endq"

qtext ::== (^'"')["\"]

endq ::== [^"\\"]

space ::== *(" ")

qpair ::== "\\."

shortcode-address ::== shortcode-string

shortcode-string ::== *(ALPHA DIGIT "!" '"' "$" "%" "&"

"/" "(" ")" "+" "*" "." "-"

"/" "=" "< ">" "[" "]" "_"

"^" "?" "{" "}" "'" "~" ";"

applicationID-symbol ::== ALPHA DIGIT "." "_"

例子:

"mms://+14165552112"

"mms://richard@sun.com"

"mms://+16475551212:com.sun.wireless.photo"

"mms://:com.sun.wireless.voicenote"

原文请参考这里

(出处:http://www.knowsky.com)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有