当前位置: 首页 > 工具软件 > SyncML > 使用案例 >

手机开发实战134——SyncML介绍3

卫烨烁
2023-12-01

SyncML同步协议

3.1 动机: 
   
  表示协议并不足够来实现信息的交互性 
  可以在多种设备之间传输多种格式的数据 
   
  3.2 设计原则 
   
  满足网络延迟的需要 
  满足各种设备 
  满足现有的各种储存模式 
  满足多种安全需求 
  多种使用模式 
   
  3.3 Sync 类型 
  3.3.1双向同步 
   
  客户端和服务器端双向传输信息 
  在特殊情况下采用Slow sync 作为传输模式 
  3.3.2 客户端单向同步 
   
  只有客户端提出修改信息 
  特殊情况下,数据可以被输出 
  3.3.3 服务器端单向同步 
   
  只有服务器端提出修改信息 
  特殊情况下,数据可以被输入 
  3.3.4 服务器端通告 
   
  同步要求从服务器端传到客户端 
  3.3.5 双向同步例子 
   
  日历的同步传输 
  客户端的认证请求被接受 
  客户端传送两条信息 
  服务器端传送一条信息 
  服务器端和客户端的数据一致会立刻完成 
  下面是一个例子,描述同步传输的大体过程。同步传输有七种方式,下面的例子是双向传输,最复杂的一种。首先进行初始的准备工作,然后进行传输,再进行确认。 
   
  3.3.5.1客户端发出同步请求 
  < SyncML> 
  相当于同步的头文件,基本为固定模式 
  < SyncHdr> 
  < VerDTD>1.0< /VerDTD> 
  < VerProto>SyncML/1.0< /VerProto> 
  < SessionID>1< /SessionID> 
  < MsgID>1< /MsgID> 
  同步初始化时数值为一,相当于第几个回合 
  目标地址 
  < Target>< LocURI>http://www.syncml.org/sync-server< /LocURI>< /Target> 
  源地址 
  < Source>< LocURI>IMEI:493005/10/059280/0< /LocURI>< /Source> 
  认证 
  < Cred> < !--The authentication is optional.--> 
  认证模式 
  < Meta>< Type xmlns='syncml:metinf'>syncml:auth-basic< /Type>< /Meta> 
  相当于密码 
  < Data>dXNlcmlkOnBhc3N3b3Jk=< /Data> < !--base64 formatting of "userid:password"--> 
  < /Cred> 
  < Meta> < !--The Meta is now used to indicate the maximum SyncML message size, which 
  client can receive.--> 
  < mi:MaxMsgSize xmlns:mi='syncml:metinf'>5000< /mi:MaxMsgSize> 
  < /Meta> 
  < /SyncHdr> 
  头文件结束 
  < SyncBody> 
  唤醒对方,相当于发出信号 
  < Alert> 
  < CmdID>1< /CmdID> 
  命令ID
  < Data>200< /Data> < !-- 200 = TWO_WAY_ALERT --> 
  共有七种连接方式,200代表其中一种 
  < Item> 
  < Target>< LocURI>./contacts/james_bond< /LocURI>< /Target> 
  进行操作的目标和地址,相当于数据库 
  < Source>< LocURI>./dev-contacts< /LocURI>< /Source> 
  < Meta> 
  相当于认证 
  < Anchor xmlns='syncml:metinf'> 
  < Last>234< /Last> 
  < Next>276< /Next> 
  < /Anchor> 
  < /Meta> 
  < /Item> 
  < /Alert> 
  上传 
  < Put> 
  < CmdID>2< /CmdID> 
  < Meta>< Type xmlns='syncml:metinf'>application/xml< /Type>< /Meta> 
  固定的格式 
  < Item> 
  < Source>< LocURI> devinf10< /LocURI>< /Source> 
  固定的格式 
  < Data> 
  < DevInf xmlns='syncml:devinf'> 
  相当于本地的数据描述 
  < Man>Big Factory, Ltd.< /Man> 
  < Mod>4119< /Mod> 
  < OEM>Jane's phones< /OEM> 
  < FwV>2.0e< /FwV> 
  < SwV>2.0< /SwV> 
  < HwV>1.22I< /HwV> 
  < DevId>1218182THD000001-2< /DevId> 
  < DevTyp>phone< /DevTyp> 
  < DataStore> 
  < SourceRef>./contacts< /SourceRef> 
  < DisplayName>Phonebook< /DisplayName> 
  < MaxGUIDSize>32< /MaxGUIDSize>GUID 
  相当于索引 
  < Rx-Pref> 
  < CTType>text/x-vcard < /CTType> 
  < VerCT>2.1< /VerCT> 
  < /Rx-Pref> 
  < Tx-Pref> 
  < CTType>text/x-vcard< /CTType> 
  < VerCT>2.1< /VerCT> 
  < /Tx-Pref> 
  数据存储能力 
  < DSMem> 
  < MaxMem>32650< /MaxMem> 
  < MaxID>250< /MaxID> 
  < FreeMem>22430< /FreeMem> 
  < FreeID>122< /FreeID> 
  < /DSMem> 
  < /DataStore> 
  < CTCap> 
  < CTType>text/x-vcard< /CTType> 
  < PropName>BEGIN< /PropName> 
  < ValEnum>VCARD< /ValEnum> 
  < PropName>END< /PropName> 
  < ValEnum>VCARD< /ValEnum> 
  < PropName>VERSION< /PropName> 
  < ValEnum>2.1< /ValEnum> 
  < PropName>N< /PropName> 
  < PropName>TEL< /PropName> 
  < ParamName>VOICE< /ParamName> 
  < ParamName>CELL< /ParamName> 
  < /CTCap> 
  < SyncCap> 
  < SyncType>01< /SyncType> 
  < SyncType>02< /SyncType> 
  < /SyncCap> 
  < /DevInf> 
  < /Data> 
  < /Item> 
  < /Put> 
  < Get> 
  < CmdID>3< /CmdID> 
  < Meta>< Type xmlns='syncml:metinf'>application/xml< /Type>< /Meta> 
  < Item> 
  < Target>< LocURI> devinf10< /LocURI>< /Target> 
  < /Item> 
  < /Get> 
  < Final/> 
  < /SyncBody> 
  < /SyncML>

3.3.5.2服务器端发出同步请求 
  < SyncML> 
  头文件 
  < SyncHdr> 
  < VerDTD>1.0< /VerDTD> 
  < VerProto>SyncML/1.0< /VerProto> 
  < SessionID>1< /SessionID> 
  < MsgID>1< /MsgID> 
  < Target>< LocURI>IMEI:493005/10/059280/0< /LocURI>< /Target> 
  < Source>< LocURI>http://www.syncml.org/sync-server< /LocURI>< /Source> 
  < Cred> < !--The authentication is optional.--> 
  < Meta>< Type xmlns='syncml:metinf'>syncml:auth-basic< /Type>< /Meta> 
  < Data>dXNlcmlkOnBhc3N3b3Jk=< /Data> < !--base64 formatting of "userid:password"--> 
  < /Cred> 
  < /SyncHdr> 
   
  < SyncBody> 
  相当于回复客户端请求 
  回复头文件 
  < Status> 
  < MsgRef>1< /MsgRef>< CmdRef>0< /CmdRef>< Cmd>SyncHdr< /Cmd> 
  < TargetRef>http://www.syncml.org/sync-server< /TargetRef> 
  < SourceRef>IMEI:493005/10/059280/0< /SourceRef> 
  212代表正常 
  < Data>212< /Data> < !--Statuscode for OK, authenticated for session--> 
  < /Status> 
  回复Alert 
  < Status> 
  < MsgRef>1< /MsgRef>< CmdRef>1< /CmdRef>< Cmd>Alert< /Cmd> 
  < TargetRef>./contacts/james_bond< /TargetRef> 
  < SourceRef>./dev-contacts< /SourceRef> 
  < Data>200< /Data> < !--Statuscode for OK--> 
  200代表正常 
  把认证对上,对方请求的值 
  < Item> 
  < Data>< Anchor xmlns='syncml:metinf'>< Next>276< /Next>< /Anchor>< /Data> 
  < /Item> 
  < /Status> 
  < Status> 
  回复Put 
  < MsgRef>1< /MsgRef>< CmdRef>2< /CmdRef>< Cmd>Put< /Cmd> 
  < SourceRef> devinf10< /SourceRef> 
  < Data>200< /Data> < !--Statuscode for OK--> 
  < /Status> 
  返回值,请求对方 
  < Results> 
  < MsgRef>1< /MsgRef>< CmdRef>3< /CmdRef> 
  < Meta>< Type xmlns='syncml:metinf'>application/xml< /Type>< /Meta> 
  固定格式 
  < Item> 
  < Source>< LocURI>devinf10< /LocURI>< /Source> 
  固定格式 
  < Data> 
  相当于数据描述 
  < DevInf xmlns='syncml:devinf'> 
  < Man>Small Factory, Ltd.< /Man> 
  < Mod>Tiny Server< /Mod> 
  < OEM>Tiny Shop< /OEM> 
  < DevId>485749KR< /DevId> 
  < DevTyp>Server< /DevTyp> 
  < DataStore> 
  < SourceRef>./contacts< /SourceRef> 
  < DisplayName>Addressbook< /DisplayName> 
  < Rx-Pref> 
  < CTType>text/x-vcard < /CTType> 
  < VerCT>2.1< /VerCT> 
  < /Rx-Pref> 
  < Rx> 
  < CTType>text/vcard < /CTType> 
  < VerCT>3.0< /VerCT> 
  < /Rx> 
  < Tx-Pref> 
  < CTType>text/x-vcard< /CTType> 
  < VerCT>2.1< /VerCT> 
  < /Tx-Pref> 
  < Tx> 
  < CTType>text/vcard< /CTType> 
  < VerCT>3.0< /VerCT> 
  < /Tx> 
  存储能力 
  < DSMem> 
  < MaxMem>132650< /MaxMem> 
  < MaxID>1250< /MaxID> 
  < FreeMem>122430< /FreeMem> 
  < FreeID>1122< /FreeID> 
  < /DSMem> 
  < /DataStore> 
  < CTCap> 
  < CTType>text/x-vcard< /CTType> 
  < PropName>BEGIN< /PropName> 
  < ValEnum>VCARD< /ValEnum> 
  < PropName>END< /PropName> 
  < ValEnum>VCARD< /ValEnum> 
  < PropName>VERSION< /PropName> 
  < ValEnum>2.1< /ValEnum> 
  < PropName>N< /PropName> 
  < PropName>TEL< /PropName> 
  < ParamName>VOICE< /ParamName> 
  < ParamName>CELL< /ParamName> 
  < CTType>text/vcard< /CTType> 
  < PropName>BEGIN< /PropName> 
  < ValEnum>VCARD< /ValEnum> 
  < PropName>END< /PropName> 
  < ValEnum>VCARD< /ValEnum> 
  < PropName>VERSION< /PropName> 
  < ValEnum>3.0< /ValEnum> 
  < PropName>N< /PropName> 
  < PropName>TEL< /PropName> 
  < ParamName>VOICE< /ParamName> 
  < ParamName>FAX< /ParamName> 
  < ParamName>CELL< /ParamName> 
  < CTType>text/vcard< /CTType> 
  < PropName>BEGIN< /PropName> 
  < ValEnum>VCARD< /ValEnum> 
  < PropName>END< /PropName> 
  < ValEnum>VCARD< /ValEnum> 
  < PropName>VERSION< /PropName> 
  < ValEnum>3.0< /ValEnum> 
  < PropName>N< /PropName> 
  < PropName>TEL< /PropName> 
  < ParamName>VOICE< /ParamName> 
  < ParamName>FAX< /ParamName> 
  < ParamName>CELL< /ParamName> 
  < /CTCap> 
  < SyncCap> 
  < SyncType>01< /SyncType> 
  < SyncType>02< /SyncType> 
  < SyncType>07< /SyncType> 
  < /SyncCap> 
  < /DevInf> 
  < /Data> 
  < /Item> 
  < /Results> 
  进行双向传输,唤醒对方 
  < Alert> 
  < CmdID>1< /CmdID> 
  < Data>201< /Data> < !-- 201 = TWO_WAY_ALERT --> 
  < Item> 
  < Target>< LocURI>./dev-contacts< /LocURI>< /Target> 
  < Source>< LocURI>./contacts/james_bond< /LocURI>< /Source> 
  < Meta> 
  发送认证 
  < Anchor xmlns='syncml:metinf'> 
  < Last>200005021T081812Z < /Last> 
  < Next>200005022T093223Z < /Next> 
  < /Anchor> 
  < /Meta> 
  < /Item> 
  < /Alert> 
  < Final/> 
  < /SyncBody> 
  < /SyncML> 
  3.3.5.3客户端提交数据 
  < SyncML> 
  < SyncHdr> 
  < VerDTD>1.0< /VerDTD> 
  < VerProto>SyncML/1.0< /VerProto> 
  < SessionID>1< /SessionID> 
  < MsgID>2< /MsgID> 
  < Target>< LocURI>http://www.syncml.org/sync-server< /LocURI>< /Target> 
  < Source>< LocURI>IMEI:493005/10/059280/0< /LocURI>< /Source> 
  < /SyncHdr> 
  < SyncBody> 
  回复服务器的请求 
  < Status> 
  < MsgRef>1< /MsgRef>< CmdRef>0< /CmdRef>< Cmd>SyncHdr< /Cmd> 
  < TargetRef>IMEI:493005/10/059280/0< /TargetRef> 
  < SourceRef> http://www.syncml.org/sync-server < /SourceRef> 
  < Data>212< /Data> < !--Statuscode for OK, authenticated for session--> 
  < /Status> 
  回复服务器的请求 
  < Status> 
  < MsgRef>1< /MsgRef>< CmdRef>1< /CmdRef>< Cmd>Alert< /Cmd> 
  < TargetRef>./dev-contacts< /TargetRef> 
  < SourceRef>./contacts/james_bond< /SourceRef> 
  < Data>200< /Data> < !--Statuscode for Success--> 
  < Item> 
  < Data> 
  Anchor回复对方请求的< next> 
  < Anchor xmlns='syncml:metinf'>< Next>200005022T093223Z < /Next>< /Anchor> 
  < /Data> 
  < /Item> 
  < /Status> 
  < Sync> 
  < CmdID>1< /CmdID> 
  < Target>< LocURI>./contacts/james_bond< /LocURI>< /Target> 
  < Source>< LocURI>./dev-contacts< /LocURI>< /Source> 
  < Meta> 
  存储能力 
  < DSMem xmlns='syncml:devinf'> 
  < FreeMem>8100< /FreeMem> 
  < !--Free memory (bytes) in Calendar database _disibledevent="font-size: 12pt">  < FreeId>81< /FreeId> 
  < !--Number of free records in Calendar database--> 
  < /DSMem> 
  < /Meta> 
  < Replace> 
  < CmdID>2< /CmdID> 
  < Meta>< Type xmlns='syncml:metinf'>text/x-vcard< /Type>< /Meta> 
  < Item> 
  < Source>< LocURI>1012< /LocURI>< /Source> 
  数据项地址 
  < Data>< !--The vCard data would be placed here.-->< /Data> 
  < /Item> 
  < /Replace> 
  < /Sync> 
  < Final/> 
  < /SyncBody> 
  < /SyncML>

3.3.5.4服务器端提交数据 
  < SyncML> 
  < SyncHdr> 
  < VerDTD>1.0< /VerDTD> 
  < VerProto>SyncML/1.0< /VerProto> 
  < SessionID>1< /SessionID> 
  < MsgID>2< /MsgID> 
  < Target>< LocURI>IMEI:493005/10/059280/0< /LocURI>< /Target> 
  < Source>< LocURI>http://www.syncml.org/sync-server< /LocURI>< /Source> 
  < /SyncHdr> 
  < SyncBody> 
  回复客户请求 
  < Status> 
  < MsgRef>2< /MsgRef>< CmdRef>0< /CmdRef>< Cmd>SyncHdr< /Cmd> 
  < TargetRef>http://www.syncml.org/sync-server< /TargetRef> 
  < SourceRef>IMEI:493005/10/059280/0< /SourceRef> 
  < Data>200< /Data> 
  < /Status> 
  回复Sync请求 
  < Status>< !--This is a status for the client modifications to the server.--> 
  < MsgRef>2< /MsgRef>< CmdRef>1< /CmdRef>< Cmd>Sync< /Cmd> 
  < TargetRef>./contacts/james_bond< /TargetRef> 
  < SourceRef>./dev-contacts< /SourceRef> 
  < Data>200< /Data> < !--Statuscode for Success--> 
  < /Status> 
  回复Replace 
  < Status> 
  < MsgRef>2< /MsgRef>< CmdRef>2< /CmdRef>< Cmd>Replace< /Cmd> 
  < SourceRef>1012< /SourceRef> 
  < Data>200< /Data> < !--Statuscode for Success--> 
  < /Status> 
  发出同步请求 
  < Sync> 
  < CmdID>1< /CmdID> 
  < Target>< LocURI>./dev-contacts< /LocURI>< /Target> 
  < Source>< LocURI>./contacts/james_bond< /LocURI>< /Source> 
  < Replace> 
  < CmdID>2< /CmdID> 
  < Meta>< Type xmlns='syncml:metinf'>text/x-vcard< /type>< /Meta> 
  < Item> 
  < Target>< LocURI>1023< /LocURI>< /Target> 
  < Data>< !--The vCard data would be placed here.-->< /Data> 
  < /Item> 
  < /Replace> 
  < Add> 
  < CmdID>3< /CmdID> 
  < Meta>< Type xmlns='syncml:metinf'>text/x-vcard< /type>< /Meta> 
  < Item> 
  < Source>< LocURI>10536681< /LocURI>< /Source> 
  < Data>< !--The vCard data would be placed here.-->< /Data> 
  < /Item> 
  < /Add> 
  < /Sync> 
  < Final/> 
  < /SyncBody> 
  < /SyncML> 
  3.3.5.5客户端显示数据更改情况 
  < SyncML> 
  < SyncHdr> 
  < VerDTD>1.0< /VerDTD> 
  < VerProto>SyncML/1.0< /VerProto> 
  < SessionID>1< /SessionID> 
  < MsgID>3< /MsgID> 
  < Target>< LocURI>http://www.syncml.org/sync-server< /LocURI>< /Target> 
  < Source>< LocURI>IMEI:493005/10/059280/0< /LocURI>< /Source> 
  < /SyncHdr> 
  < SyncBody> 
  回复同步请求 
  < Status> 
  < MsgRef>2< /MsgRef>< CmdRef>0< /CmdRef>< Cmd>SyncHdr< /Cmd> 
  < TargetRef>IMEI:493005/10/059280/0< /TargetRef> 
  < SourceRef> http://www.syncml.org/sync-server < /SourceRef> 
  < Data>200< /Data> 
  < /Status> 
  < Status> 
  < MsgRef>2< /MsgRef>< CmdRef>1< /CmdRef>< Cmd>Sync< /Cmd> 
  < TargetRef>./dev-contacts< /TargetRef> 
  < SourceRef>./contacts/james_bond< /SourceRef> 
  < Data>200< /Data> 
  < /Status> 
  < Status> 
  < MsgRef>2< /MsgRef>< CmdRef>2< /CmdRef>< Cmd>Replace< /Cmd> 
  < TargetRef>1023< /TargetRef> 
  < Data>200< /Data> 
  < /Status> 
  < Status> 
  < MsgRef>2< /MsgRef>< CmdRef>3< /CmdRef>< Cmd>Add< /Cmd> 
  < SourceRef>10536681< /SourceRef> 
  < Data>200< /Data> 
  < /Status> 
  < Map>服务器和客户端的数据保持同步 
  < CmdID>1< /CmdID> 
  < Target>< LocURI>./contacts/james_bond< /LocURI>< /Target> 
  < Source>< LocURI>./dev-contacts< /LocURI>< /Source> 
  < MapItem> 
  105366811024指的是同一个数据 
  < Target>< LocURI>10536681< /LocURI>< /Target> 
  < Source>< LocURI>1024< /LocURI>< /Source> 
  < /MapItem> 
  < /Map> 
  < Final/> 
  < /SyncBody> 
  < /SyncML> 
  3.3.5.6服务器端确认更改 
  < SyncML> 
  < SyncHdr> 
  < VerDTD>1.0< /VerDTD> 
  < VerProto>SyncML/1.0< /VerProto> 
  < SessionID>1< /SessionID> 
  < MsgID>3< /MsgID> 
  < Target>< LocURI>IMEI:493005/10/059280/0< /LocURI>< /Target> 
  < Source>< LocURI>http://www.syncml.org/sync-server< /LocURI>< /Source> 
  < /SyncHdr> 
  < SyncBody> 
  < Status> 
  < MsgRef>3< /MsgRef>< CmdRef>0< /CmdRef>< Cmd>SyncHdr< /Cmd> 
  < TargetRef>http://www.syncml.org/sync-server< /TargetRef> 
  < SourceRef>IMEI:493005/10/059280/0< /SourceRef> 
  < Data>200< /Data> 
  < /Status> 
  证实数据已经做了更改 
  < Status> 
  < MsgRef>3< /MsgRef>< CmdRef>1< /CmdRef>< Cmd>Map< /Cmd> 
  < TargetRef>./contacts/james_bond < /TargetRef> 
  < SourceRef>./dev-contacts< /SourceRef> 
  < Data>200< /Data> 
  < /Status> 
  < Final/> 
  < /SyncBody> 
  < /SyncML>

 类似资料: