Taming websockets with Coroutines, Clean Architecture and a library

Websocket integration is one of the biggest issues I had in my whole experience with Android. Why is it such a huge pain? There are several reasons behind that:

  1. Connection should remain stable no matter what – and we know how complex the Android lifecycle can be.
  2. Sending data can be a one-way operation without giving any result – did you succeed in sending it or did you fail? Only Server knows.
  3. Retrying connection or network requests can be tricky to implement – from pushing logic to interactors to having an internal logic inside a repository, be sure – nothing will work at 100%. Not even at 90% either.
  4. To get it right you need both frontend and backend collaboration. Nothing can be done if both sides do it separated from each other.
Continue reading “Taming websockets with Coroutines, Clean Architecture and a library”