Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WebSocket for Android ver.2

WebSocket for Android ver.2

Yuichi Maekawa

September 16, 2016
Tweet

More Decks by Yuichi Maekawa

Other Decks in Programming

Transcript

  1. WebSocket
    For Android ver.2
    @kaelaela(Yuichi Maekawa)
    鳥: kaelaela31
    蛸猫: kaelaela

    View full-size slide

  2. ver.1
    https://speakerdeck.com/kaelaela/websocket-for-android
    on Aug 23, 2016 @ Wantedly

    View full-size slide

  3. The next day

    View full-size slide

  4. > BROADCAST DESTROY <
    #REF! -> Broadcast Destroy: http://konifar-zatsu.hatenadiary.jp/entry/2016/07/27/020130

    View full-size slide

  5. This
    entry’s
    target
    is
    enterprise
    services.

    View full-size slide

  6. Sounds logical. I agree to you only if enterprise services.

    View full-size slide

  7. For normal mobile app
    ● Almost all services have no proxy
    ● Need real time update!(messaging app or game)
    ● Need low energy consumption!
    > If you make long polling system, the user say
     “Battery fire!” and put 1 star...

    View full-size slide

  8. Use WebSocket in peace ;-)

    View full-size slide

  9. Do you know okhttp-ws?

    View full-size slide

  10. Sample code
    ● My sample Android project
    https://github.com/kaelaela/WebSockcetSample

    View full-size slide

  11. Update of okhttp-ws
    ● Add to main repos on v3.5.0!!(SNAPSHOT now)
     PR: #2852
       https://github.com/square/okhttp/pull/2852
    compile 'com.squareup.okhttp3:okhttp-ws:3.4.1'
    compile 'com.squareup.okhttp3:okhttp:3.5.0'

    View full-size slide

  12. Update of okhttp-ws
    ● Remove ws package
    ● Add method to OkHttpClient
    okhttp3.ws.* -> okhttp3.*
    newWebSocketCall

    View full-size slide

  13. Sample code diff
    ● 3.4.1 -> 3.5.0
    https://github.com/kaelaela/WebSockcetSample/commit/45b88ad2ecc5a89dbd493
    fc3cc25152511e28529

    View full-size slide

  14. Echo test: websocket.org

    View full-size slide

  15. Echo test: websocket.org
    Supports TLS.

    View full-size slide

  16. Retrofit? -> No change.
    It will be added in v2.2!!!
    (No due date. 31% complete at 2016-09-16.)
    ● Issue #924
    ● Commit
    interface Service {
    @GET("/chat/{id}")
    Call chat(@Path("id") String id);
    }

    View full-size slide

  17. Let’s replace your http client
    with okhttp!
    If your project use okhttp.

    View full-size slide