Issues with Flutter and Phoenix Channels

We’re having some issues with our Flutter App and Phoenix Web Sockets. We know that the Backend is working properly, since the JavaScript client is fully functional. But with the Flutter app we can’t connect to the server.

final socket = PhoenixSocket("ws://###.##/socket");           
connectSocket() async {
await widget.socket.connect();
_channel = widget.socket.channel("test:lobby")
_channel.on("say", _say);
_channel.join();
}

One of the errors were gettig:

I/flutter ( 4227): WebSocket connection to ws://###.##:8080/socket?vsn=2.0.0 failed!: WebSocketException: Connection to 'http://###.##:8080/socket?vsn=2.0.0#' was not upgraded to websocket

On the client side we’re using Phoenix Wings, the port and URL are correct.
Why does this keep happening?

Are there any other libraries for Flutter with Phoenix Interactions? Is there a better documentation for phoenix_wings or for any other packages?

2 Likes

Are you sure that /socket is the websocket and not the phoenix socket? Remember a phoenix socket is a number of things, like longpolling, websockets, custom things, etc… If the phoenix socket is mounted at /socket then the websocket would generally be at /socket/websocket unless changed.

If it is a client-side phoenix library I’d imagine it already took that into account though.

Should also be using wss/https too.

1 Like

Thanks a lot for the help, it worked with me. But when I cert to wss, I encountered a new problem:

WebSocket connection to wss: // localhost: 6001 / socket / websocket? Vsn = 2.0.0 failed !: HandshakeException: Handshake error in client (OS Error:
CERTIFICATE_VERIFY_FAILED: ok (handshake.cc:354))

How can i fix it?

Where you able to fix this?