【幻灯片分享】PC与Android设备间的数据通信 | 豌豆荚实验室 孙桥 | Android DevCamp...

安卓数据分享技术实现:《PC与Android设备间的数据通信》 | Android DevCamp

话题简介:随着移动应用越来越多的依赖于服务端,开发者对数据通信协议的需求慢慢增多。 而软件版本兼容性的不同、网络环境的不同等原因,都会导致设备之间从发现到传输过程中存在不少问题。豌豆荚自行研发设计的 PMP 协议,并采用 Protobuf 等技术手段都很好的解决了不管是手机与手机还是手机与 PC 之间的通信问题。此次演讲豌豆实验室创始团队成员孙桥将以豌豆荚 PC 客户端对手机的管理及手机之间的分享功能为案例,帮助大家了解豌豆荚是如何高效的解决多设备间通信问题的。

讲师介绍:豌豆荚创始团队成员,专注于 Android 开发,目前负责豌豆荚基于 Android 客户端的数据分享功能的研究和实践。


推荐指数:3星半

推荐理由:关于数据通信协议的讲解很细致,很有价值。演讲很流畅。

不足之处:讲的有点少。

现场评分:3.6


【讲师现场靓照】


【幻灯片在线观看】*:

<iframe src="http://www.slideshare.net/slideshow/embed_code/13839298" width="597" height="486" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px" allowfullscreen=""> </iframe>

备注:* 因为炫姐姐对SlideShare这一平台的偏爱,尽管需要使点小技巧才能上传分享,但是炫姐姐还是坚持选择了这一功能强大却简洁好用的平台。一来对国外这些开发出优秀的工具和平台、造福于互联网和人类的团队表示致敬,二来则是对国内对于这些优秀的工具和平台的限制表示一下立场。读者如果不能正常浏览,那么需要像炫姐姐一样用点小技巧。而对于那些还是不知道炫姐姐在说什么的小白读者,可以移步到这里寻找解决方案


【幻灯片下载页面】: http://download.csdn.net/detail/shiningxyy/4473615 -来自CSDN下载频道(不需要积分,自由下载)


【幻灯片内容刚要】:

1. AndroidDevCampProduced by CSDN
2. PC与ANDROID设备间的数据通信孙桥,豌豆荚创始团队成员
3. 豌豆荚的手机管理任务¨  豌豆荚,简单好用的 Android 手机管理软件,管 理超过 5000w 台 Android手机。¨  豌豆荚的 Phone Management Protocol (PMP) ¤  Google Protocol Buffers ¤  协议内容
4. Google Protocol Buffers¨  Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats.
5. Google Protocol Buffersexample.protomessage Person { required string name = 1; required int32 id = 2; optional string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; }; message PhoneNumber { required string number = 1; optional PhoneType type = 2 [default = HOME]; }; repeated PhoneNumber phone = 4;}
6. Google Protocol Buffers¨  序列化public byte[] serialization() { ExampleProto.Person.Builder exampleBuilder = ExampleProto.Person.newBuilder(); exampleBuilder.setId(1); exampleBuilder.setName("sunqiao"); exampleBuilder.setEmail("sunqiao@wandoujia.com"); exampleBuilder.addPhone(PhoneNumber.newBuilder() .setType(PhoneType.WORK).setNumber("1861817****").build()); return exampleBuilder.build().toByteArray();}
7. Google Protocol Buffers¨  反序列化public ExampleProto.Person deserialization(byte[] personInBytes) { ExampleProto.Person person = null; try { person = ExampleProto.Person.parseFrom(personInBytes); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } return person; }
8. Google Protocol Buffers¨  序列化时间
9. Google Protocol Buffers¨  反序列化时间
10. Google Protocol Buffers¨  序列化后数据大小
11. Google Protocol Buffers¨  内存使用 - toByteArray()public byte[] toByteArray() { try { final byte[] result = new byte[getSerializedSize()]; final CodedOutputStream output = CodedOutputStream.newInstance(result); writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new RuntimeException( "Serializing to a byte array threw an IOException " + "(should never happen).", e); } }
12. Google Protocol Buffers¨  内存使用 – 嵌套message Parent { optional string content_type = 1; optional bytes content = 2;};message Child1 { optional int32 id = 1; optional string name = 2; optional string des = 3;};message Child2 { optional string title = 1; optional string content = 2; optional bytes icon = 3;};
13. Google Protocol Buffers¨  运行库大小¨  optimize_for ¤  SPEED ¤  CODE_SIZE ¤  LITE_RUNTIME
14. Google Protocol Buffers ¨  运行库大小Feature protobuf Protobuf (lite-runtime) Protobuf-j2meRuntime library size 420KB 77KB 22KBGenerated code 100% 73% 26%sizeEnumerations YES YES YESUnknown fields YES YES NOImmutability YES YES NOGroups YES YES NOReflection YES NO NODescriptors YES NO NO
15. Phone Management Protocol¨  消息格式 ¤  Request n  Header n  Token,用于标识请求,并且Token中包含安全验证信息 n  Service Uri,服务地址,pmp://contact/getContacts n  Client,发起这次请求的客户端 n  Content-Range,请求的数据范围 n  Body n  Parameters,参数为键值对
16. Phone Management Protocol¨  消息格式 ¤  Response n  Header n  Token,用于标识某个请求的响应 n  Content-Type,用于标识Body中的数据类型 n  Content-Length,用于标识Body中的数据长度 n  Content-Range,用于标识Body中包含的数据在整个请求结果 中的范围 n  StatusCode,类似与Http 1.1 的 StatusCode n  Body
17. Phone Management Protocol¨  Content-Type ¤  类似于MIMEType,一个字符串对应一个使用 protobuf定义的类型,作为PMP的类型体系 vnd.pmp.item/int -> BaseProto.Int vnd.pmp.dir/int -> BaseProto.Ints
18. Phone Management Protocol¨  Service Uri ¤  服务地址,例如 pmp://sms/receive¨  目前有四种类型的服务 ¤  普通服务 ¤  支持 Content-Range 的服务 ¤  支持 Partial-Return 的服务 ¤  支持 Keep-Alive 的服务
19. Phone Management Protocol ¨  普通服务 Respo n Head se er Token t :Reques Conte 12345** r Heade 2345*** vnd.p nt-Type: * 1 mp Token: pmp://sms/ Conte .item/int : n Ser vice unt Statu t-Length:1 SCo getSM DA_PC_XXX X Body sCode:20 0 Client: 1 (pr otobu Body f seri alize d)
20. Phone Management Protocol ¨  支持 Content-Range 的服务 Respo n Head se er tReques Token : r Heade 2345*** Conte 12345** 1 Token: pmp://file/w rite vnd.p nt-Type: * mp : Ser vice _PC_XXXX /1400 Conte .item/int n DA Client: Range: 0-10 23 Statu t-Length:4 Conten t- Body sCode:20 tr> 0 B ody .pmp.item/s yte> 1024 (prot <pa th, vnd .pmp.dir/b obuf t, vnd seria < conten lized )
21. Phone Management Protocol ¨  支持 Partial-Return 的服务 Respo n Head se er Token : t Conte 12345**Reques app nt-Type: v * r nd.pm Heade 2345*** Conte p.dir/ 1 list Token: pmp://app/ Statu nt-Le n : Ser vice _PC_XXXX sCod gth:10204 Conte e:2 Client: DA nt-Ra 06 X 30 int> Body nge: Body .pm p.item/ 0-9/ y pe, vnd apps 300 <appT (prot obuf seria lized Conte ) nt-Ty Conte pe nt-Le : vnd.pmp Statu n .dir/i Body sCod gth:4 nt e:200 Body 300 (prot obuf seria lized
22. Phone Management Protocol ¨  支持 Keep-Alive 的服务 Respo n Head se er Token : Conte 12345**Reques t notifi nt-Type: v * r cat nd.pm Heade 2345*** ait Conte ion p.dir/ 1 c ation/w nt-Le Token: pmp://notifi Statu n : sCod gth:1024 Ser vice _PC_XXXX Conte e:2 DA nt-Ra 06 X ttl Client: Body nge: nt> 0-1/ Body .pmp.item/i notifi catio ttl < ttl, vnd n (pro tobuf seria Conte .. Conte nt-Type: v n n Statu t-Length:4 d.pmp.dir Body sCode:20 /int 0 ttl (p rotob uf se rializ ed
23. Phone Management Protocol¨  安全性 ¤  使用Token来验证请求是否非法,Token中包含了安 全信息(必须是手机授权的客户端才能访问),具 体算法不详
24. Phone Management Protocol¨  兼容性 ¤  兼容性问题是由于对协议进行升级导致的出现不同的协议版 本的客户端和服务器端相互请求的问题 ¤  产生兼容性问题的原因 n  修改方法接口定义 n  修改数据结构定义 n  修改安全验证方式 n  性能优化,使用了新的序列化/反序列化方法 ¤  解决方案 n  不修改删除已有方法,只新增方法 n  不修改删除已有数据结构字段,只新增新的字段 n  只有一种安全验证方式 n  只使用protobuf进行序列化和反序列化
25. Q&A

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值