How to send keep alive packets to maintain a realtime web socket via Cloudflare?
- 0
- Flutter
- Realtime
I think the realtime API for appwrite might be standard enough that using that websocket package might be easier than forking the appwrite sdk.
From looking at the realtime network requests
If you try it report back how it goes
Got it working:
Used a more popular web socket package than the one you linked so I don't have to worry about it being supported long term.
It'll log the heartbeats:
Good to know that it works. web socket channel is somewhat the official version for using websockets, the library I suggested is just a package using it below with their own retry logic and all that jazz on top. the maintainer ain't a noname tho. He is responsible for bloc, mason and other top packages and a well known figure. Nonetheless a good approach you did there
Does is counter the cloudflare 100s disconnect?
Yes. The logs you see above are to a hosted thru cloudflare appwrite cluster.
Didn't see that, I might pop that package in right now because the retry logic is kinda nice.
It's really needed. I have worked with on a different project where they used websockets and the official package is literally unusable without retry logic.
Because disconnects can happen and especially when the app gets put into the background the realtime connection just gets dropped
or when put into doze which can happen after a few seconds if the app is in the background
Here's the updated one using the other package. Stays connected and has a bit better error handling too 🎉
@Joshi
That's great <a:aPES2_Crazy:525603278830960640>
Have you tried to put the app into doze?
From my experience it takes around 90-120 seconds but would be nice to see if it reconnects afterwards
Haven't tried doze. But with the combination of the subscription onDone trigger and AppLifeCycle it should be achievable.
It should reconnect even withput AppLifeCycle no?
The fancy package is having issues with the timeout not working for Cloudflare and just reconnects the websocket when it fails every 100 secs. I already had retry logic built into the more popular package, so I'm using that one. Not as fancy retry logic, but it's not hard to implement what is needed.
Can you go a bit more into detail what you mean
I couldn't get the timeout to work with the web_socket_client
package. So I'm using other package because I can control what is sent as the heartbeat package and when it is sent too (doesn't need to be sent until 100 sec after the last sent package).
It's working well. The only downside is I have to manage the reconnect logic myself which isn't hard.
Recommended threads
- Current User is Not authorized
recreating same Thread
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...
- Sign In With Apple OAuth Help
Hi All! I've got a flutter & appwrite app which Im trying to use sign in with apple for. I already have sign in with google working and the function is the sam...