Skip to content
Back

Cannot subscribe to channel through Realtime: WebSocketChannelException: WebSocket connection failed

  • 1
  • Flutter
  • Realtime
hernik
22 Aug, 2023, 20:05

Hello, I am trying to subscribe to a channel using Realtime in my flutter app. I have the following code:

TypeScript
var sub = realtime.subscribe(
      ["databases.main.collections.teachers.documents"]);

And then have a function which simply calls sub.stream.listen to listen. When I launch the app, I only get the WebSocketChannelException and in the devtools console of my browser I get can’t establish a connection to the server... and that the websocket returned an error 400. I tried to look into the appwrite-realtime container logs and it simply listed Connection close: N over and over. I am pretty sure the realtime endpoint is correct and the collection has its collections permission currently set to allow anyone to read. But I still cannot figure out where is the problem.

TL;DR
User is having trouble subscribing to a channel through Realtime in a Flutter app. They are receiving a WebSocketChannelException and a WebSocket error 400. They have checked the appwrite-realtime container logs and the collection's permissions. They are using Nginx, Plesk, and Cloudflare as proxies. The solution suggested is to check if websockets are enabled in Nginx and if traefik trusts both proxies.
D5
22 Aug, 2023, 20:33

Is this self-hosted?

hernik
22 Aug, 2023, 20:33

yes

D5
22 Aug, 2023, 20:40

@hernik Are you using any proxy like Nginx, Plesk, Cloudflare....?

hernik
22 Aug, 2023, 20:40

Currently my Appwrite is connected Appwrite -> Nginx -> Cloudflare

D5
22 Aug, 2023, 20:41

Maybe that's the issue. Did you have setup traefik to trust both proxys?

hernik
22 Aug, 2023, 20:43

I think cloudflare should be ok, but I have no idea how to check if traefik trusts both proxies, do you happen to have some docs on how to check/set that please?

hernik
22 Aug, 2023, 21:15

Added, restarted and still the same problem :(

Drake
23 Aug, 2023, 23:32

Did you enable websockets in nginx?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more