You have to use foreground services to allow running the websocket as service even with the screen turned-off
So you will instantiate inside this service a websocket client class from some library, that will allow you to treat the websocket connection (onOpen, OnClosed) In the onFailure event in the websocket client, you can schedule a reconnection that will be triggered from the websocket service to restart a new websocket client object.
I am using Kotlin.
https://developer.android.com/develop/background-work/services/fgs