Search code examples
androidkotlinwebsocketphoenix-frameworkphoenix-channels

How can I connect to Phoenix channels from a Kotlin Android app?


I'm thinking of building a full-stack project with an Elixir Phoenix backend and a Kotlin Android client.

The app will require real-time data for features similar to chatting, so I will have to use Phoenix Channels. After a quick research, I found out that Phoenix has some sort of an extra layer on top of the classic WebSocket logic, which I have to use.

And I have no idea of how to do that, or if there is a library to use for that. I saw some libraries on GitHub but I don't know how performant they are, so I'm not really sure if I want to use them.

It would be really nice if someone could explain how it works and if I need extra tools alongside classic Retrofit (or Ktor Client) to send and receive real-time data between a Phoenix backend and a Kotlin Android client.

I already know how to do stuff like HTTP requests, mostly CRUD with a Phoenix backend and a Kotlin Android app, but I never implemented any real-time features with a Phoenix backend and a Kotlin Android app before.

Thanks!


Solution

  • You don't "have" to use Phoenix Channels. Channels does not suit everyone's need. You can use regular "raw" Socket to connect between your front and backend, using Erlang's gen_tcp, or ssl. Phoenix is web framework to ease your developer life doing web development. Of course you can use it to communicate with most Apps, but it is not always the best choice.

    However, you can find the Java equivalent of phoenix.js which support Phoenix Channels here : https://github.com/dsrees/JavaPhoenixClient