Skip to content
Back

[Urgent] Flutter Realtime Subscription

  • 0
  • Flutter
DanFQ
11 Apr, 2025, 16:38

Hello everyone!

I've been trying, for hours, to get Realtime to work in my Flutter App (for a client). The subscription always fails, logging this to the console:

TypeScript
I/flutter (25446): Reconnecting in 1 seconds.```

As far as I know, that ":0" isn't supposed to be there.
I've triple-checked my Endpoint and it is correct.

My AppWrite instance is self-hosted, on my VPS.
These are my Apache directives:

Preserve Host headers and set X-Forwarded headers

ProxyPreserveHost On RequestHeader set X-Forwarded-Proto "https" RequestHeader set X-Forwarded-Port "443"

Enable WebSocket Support

RewriteEngine On RewriteCond %{HTTP:Connection} Upgrade [NC] RewriteCond %{HTTP:Upgrade} =websocket [NC] RewriteRule /(.*) "ws://127.0.0.1:8080/$1" [P,L]

WebSocket location for realtime

ProxyPass "/v1/realtime/" "ws://127.0.0.1:8080/v1/realtime/" ProxyPassReverse "/v1/realtime/" "ws://127.0.0.1:8080/v1/realtime/"

Forward everything else (Appwrite Dashboard and REST API)

ProxyPass "/" "http://127.0.0.1:8080/" ProxyPassReverse "/" "http://127.0.0.1:8080/"

TypeScript

A cURL command I used to check functionality:

curl -i -N
\ -H "Connection: Upgrade"
\ -H "Upgrade: websocket"
\ -H "Host: appwrite.danfq.dev"
\ -H "Origin: https://appwrite.danfq.dev"
\ "https://appwrite.danfq.dev/v1/realtime?project=bubbl&channels%5B%5D=databases.main.collections.winks.documents"

TypeScript

The response:

HTTP/2 400 server: nginx date: Fri, 11 Apr 2025 16:56:00 GMT content-type: text/html; charset=UTF-8 content-length: 83 cache-control: must-revalidate,no-cache,no-store

<html><body><h2>HTTP 400 Bad Request</h2><hr><i>Powered by Swoole</i></body></html> ```

Any ideas? Thanks in advance!

TL;DR
Developers having trouble with Realtime Subscription in Flutter App due to WebSocketException with HTTP status code 400. The issue may be related to Apache directives. Ensure WebSocket location for realtime is properly configured. Test functionality with cURL command.
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