Problem with Phoenix Channels Client for Android

Hey, guys.

Have a problem with Channels client for Android. Here’s the lib I’m using: https://github.com/eoinsha/JavaPhoenixChannels.

Created an experimental channel in phoenix app, running on localhost, but can’t connect to it from my Android client, running in emulator. Everything is ok with channel, because JavaScript client, shipped with Phoenix, can connect and work with it.

Trying to connect to “ws://localhost:4000/socket/websocket”, as library docs suggest, but getting this error message: “java.net.ConnectException: Failed to connect to localhost/127.0.0.1:4000”.

Any ideas will be much appreciated, guys.

Thanks.

Are you running the phoenix server on the Android device? If not then connecting to localhost (the ‘local’ host) is not what you want. ^.^

2 Likes

Ok, was guessing that can be the issue. I’m running server on computer, nor in emulator, neither in device.

Is there a way to test channels from Android apps, while developing, other then deploying to remote servers and connecting with “full-featured” URIs?

As long as the android application has network access then just access the IP of the computer that is running the phoenix server and make sure phoenix binds to that IP (which it does by default in development mode). :slight_smile:

It’s exactly the same as if testing any other networked app. :slight_smile:

2 Likes

Thanks a lot. It’s working now ))

1 Like

Another issue, guys.

Seems, deserialization of server responses now causes a problem. I’m getting this error on Android: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "join_ref" (class org.phoenixframework.channels.Envelope), not marked as ignorable (4 known properties: "event", "ref", "payload", "topic"]), with this error message: Failed to read message payload

Basically, class Envelope expecting 4 properties, but gets 5 - the “join_ref” and fails on it. I tried to mark methods receiving "Envelop"s with Jacksons’ @JsonIgnoreProperties(ignoreUnknown = true), but it didn’t help. Suggestions are either to mark POJO class (Envelope, in this case) with it (don’t have access to it, as it comes with channels client lib), or configure ObjectMapper, but server response is mapped already, when it reaches to my code.

Any suggestions, guys?

Yeah there is indeed a join_ref in the JSON (why is your namespace referencing xml?!?), so that seems like a bug in whatever channel library that is, should submit a bug report. :slight_smile:

Have no idea. It’s Jackson lib, maybe there company domain or stuff like that.

Checked channel library git repo, there’s a bug report and even solution to it already (commit almost 3 months old), waiting for author to merge it.

If anyone is interested, solution was to mark Envelope.java class with @JsonIgnoreProperties(ignoreUnknown = true) annotation.

Thanks, @OvermindDL1 ))

1 Like