Tuesday, 1 June 2021

Convert existing WebSocket implementation into Reactive WebSocket in Android Java

I am using OKHttpClient with WebSockets in Android. I want to convert it into reactive programming. How to achieve this. For now i am doing this for WebSocket Connection.

    // OkHttp Client
    OkHttpClient httpClient = new OkHttpClient.Builder().build();

    // WebSocket Object
    Request request = new Request.Builder().url(url).build();
    mWebSocket = httpClient.newWebSocket(request, new WebSocketListener() {
        // Override methods - OnOpen, OnMessage, OnClosing, OnFailure
    }

    // Then Calling this to make websocket request
    mWebSocket.send(message);

I have found this library to use Reactive WebSocket https://github.com/jacek-marchwicki/JavaWebsocketClient

But there is no Callback Listener as 'WebSocketListener' so i can handle the messages.

Any help would be appreciated in this direction. Thanks



from Convert existing WebSocket implementation into Reactive WebSocket in Android Java

No comments:

Post a Comment