【投影片分享】PC與Android裝置間的資料通訊 | 豌豆莢實驗室 孫橋 | Android DevCamp

來源:互聯網
上載者:User

安卓資料分享技術實現:《PC與Android裝置間的資料通訊》 | Android DevCamp

話題簡介:隨著行動裝置 App越來越多的依賴於服務端,開發人員對資料通訊協定的需求慢慢增多。 而軟體版本相容性的不同、網路環境的不同等原因,都會導致裝置之間從發現到傳輸過程中存在不少問題。豌豆莢自行研發設計的 PMP 協議,並採用 Protobuf 等技術手段都很好的解決了不管是手機與手機還是手機與 PC 之間的通訊問題。此次演講豌豆實驗室創始團隊成員孫橋將以豌豆莢 PC 用戶端對手機的管理及手機之間的分享功能為案例,協助大家瞭解豌豆莢是如何高效的解決多裝置間通訊問題的。

講師介紹:豌豆莢創始團隊成員,專註於 Android 開發,目前負責豌豆莢基於 Android 用戶端的資料分享功能的研究和實踐。

推薦指數:3星半

推薦理由:關於資料通訊協定的講解很細緻,很有價值。演講很流暢。

不足之處:講的有點少。

現場評分:3.6

【講師現場靚照】

【投影片線上觀看】*:

發現和建立多裝置之間的資料通訊 | 豌豆莢實驗室 孫橋 from Shining @DevCamp

備忘:* 因為炫姐姐對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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.