Java and Android channel client for the Phoenix Framework
Switch branches/tags
Nothing to show
Clone or download
bryanjos Merge pull request #48 from jpage4500/okhttp-update
Replace okhttp-ws with official okhttp websocket implementation
Latest commit ac6d93d Mar 10, 2017

Phoenix Channel Client for Java and Android

JavaPhoenixChannels is a Java and Android client library for the Channels API in the Phoenix Framework. Its primary purpose is to ease development of real time messaging apps for Android using an Elixir/Phoenix backend. For more about the Elixir language and the massively scalable and reliable systems you can build with Phoenix, see and

Including the Library

  • Add as a Maven repository
  • Add JavaPhoenixChannels as an app dependency:
dependencies {
  compile('com.github.eoinsha:JavaPhoenixChannels:0.2') {
      exclude module: 'groovy-all'


Example Android App

For a full sample Android chat app, check out the repository at

The quick examples below are used with the Phoenix Chat Example

Example using Groovy

import org.phoenixframework.channels.*
def socket = new Socket('ws://localhost:4000/socket/websocket')
def chan = socket.chan()
chan.join("rooms:lobby", null)
    .receive("ignore", { -> println "IGNORE"})
    .receive("ok", { envelope -> println "JOINED with $envelope" })
chan.on('new:msg', { -> println "NEW MESSAGE: $envelope"})

Example using Java

import org.phoenixframework.channels.*;

Socket socket;
Channel channel;

socket = new Socket("ws://localhost:4000/socket/websocket");

channel = socket.chan("rooms:lobby", null);

.receive("ignore", new IMessageCallback() {
    public void onMessage(Envelope envelope) {
.receive("ok", new IMessageCallback() {
    public void onMessage(Envelope envelope) {
        System.out.println("JOINED with " + envelope.toString());

channel.on("new:msg", new IMessageCallback() {
    public void onMessage(Envelope envelope) {
        System.out.println("NEW MESSAGE: " + envelope.toString());

channel.on(ChannelEvent.CLOSE.getPhxEvent(), new IMessageCallback() {
    public void onMessage(Envelope envelope) {
        System.out.println("CLOSED: " + envelope.toString());

channel.on(ChannelEvent.ERROR.getPhxEvent(), new IMessageCallback() {
    public void onMessage(Envelope envelope) {
        System.out.println("ERROR: " + envelope.toString());

//Sending a message. This library uses Jackson for JSON serialization
ObjectNode node = new ObjectNode(JsonNodeFactory.instance)
        .put("user", "my_username")
        .put("body", message);

channel.push("new:msg", node);


To contribute, see the contribution guidelines and instructions.