WebSocket for Android

WebSocket for Android

A967476c5855d593710a9a580f6b2aed?s=128

Yuichi Maekawa

August 23, 2016
Tweet

Transcript

  1. WebSocket  For Android @kaelaela(Yuichi Maekawa) Twitter: kaelaela31 Github: kaelaela

  2. Overview of WebSocket • Bidirectional communication • port: 80 or

    443 • scheme: ws or wss • binary support • RFC6455
  3. Pros • No request header(So, hi-Speed!) • Real time communication

    • available HTTP resource(proxy, filter, auth...)
  4. Cons • Difficult error handling • Difficult re-connection handling •

    Do not control message priority
  5. Popular WebSocket libraries • Socket.io • Java-websocket • Okhttp-ws •

    java.net.Socket
  6. Using WebSocket with OkHttp • Repos    https://github.com/square/okhttp/tree/master/okhttp-ws Note: This

    module's API should be considered experimental and may be subject to breaking changes in future releases.
  7. Using WebSocket with OkHttp • add dependencies ※ need permission:

    android.permission.INTERNET • create WebSocketListener extends class …show my sample code. compile 'com.squareup.okhttp3:okhttp-ws:3.4.1'
  8. Sample code • Okhttp-ws: repo   Only 7 classes :-)   sample

    class: WebSocketEcho.java WebSocet test: https://www.websocket.org/echo.html • My sample https://github.com/kaelaela/WebSockcetSample
  9. History of okhttp-ws • Version 2.3.0: Beta release • Version

    2.4.0-RC1: Bug fix • Version 2.4.0: WebSocketListener has incompatible changes. • Version 2.6.0: ◦ WebSocket API now uses RequestBody and ResponseBody for messages. ◦ Bug fix • Version 3.1.0: WebSockets now defer some writes. • Version 3.3.1: Bug fix
  10. Milestone of okhttp-ws v3.5(Due by August 31, 2016) • some

    bug fix v3.6(Due by September 30, 2016) • some bug fix • status code enhancement(issue) But, most issues are deferred. Let pray. more information: show websocket label
  11. Retrofit? maybe add v2.2!!!(No due date. 29% complete at 2016-08-21.)

    • Issue #924 • Commit interface Service { @GET("/chat/{id}") Call<WebSocket> chat(@Path("id") String id); }
  12. Thx ;-) Http2? I don’t know.