Today Jake Wharton posted an announcement on his medium blog that OkHttp version 3.5 released today includes support for Web Sockets.
Web Sockets provide full-duplex communication channels over a single tcp connection and is being standardized by the W3C. The can be used to implement client server web based applications.
With the update to the library you create a new web socket by passing a request tot he newWebSocket() method along with a listener for messages sent by the server.
Web Sockets now shipping in OkHttp 3.5! – Square Corner Blog – Medium
OkHttpClient client = new OkHttpClient();
Request request = //... WebSocketListener listener = //...
WebSocket ws = client.newWebSocket(request, listener);
To use version 3.5 in your application add the library to your build.gradle file using the follinw line or via the Android Studio Dependencies tab in the Project Structure Dialog.
compile ‘com.squareup.okhttp3:okhttp:3.5.0‘
One thought on “Web Sockets come to OkHttp v3.5”