Back

[SOLVED] Unhandled Exception: WebSocketException

  • 0
  • Flutter
  • Realtime
disbold
18 Apr, 2023, 09:02

appwrite: ^9.0.0 ## flutter appwrite package version

E/flutter ( 5044): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: WebSocketException: Connection to [LINK] was not upgraded to websocket.

I am building a flutter app with Riverpod state management.

<code>sample code </code>

final appWriteRealtimeProvider = Provider((ref) { final client = ref.watch(appWriteClientProvider); return Realtime(client); });

final getLatestEweetProvider = StreamProvider((ref) { final eweetAPI = ref.watch(eweetAPIProvider); return eweetAPI.getLatestEweet(); });

@override Stream<RealtimeMessage> getLatestEweet() { return _realtime.subscribe([ 'databases.${KAppWrite.databaseId}.collections.${KAppWrite.eweetsCollection}.documents' ]).stream; }

// UI class EweetList extends ConsumerWidget { const EweetList({super.key});

@override Widget build(BuildContext context, WidgetRef ref) { return ref.watch(getEweetsProvider).when( data: (eweets) { return ref.watch(getLatestEweetProvider).when( data: (data) { return ListView.builder( itemCount: eweets.length, itemBuilder: (c, i) { return Text(i.toString()); }, ); }, error: (e, st) { log("STack trace is ${st}"); return ErrorText(error: e.toString()); }, loading: () { return ListView.builder( itemCount: eweets.length, itemBuilder: (c, i) { return TweetCard(tweet: eweets[i]); }, ); }, ); }, error: (e, st) { log("STack trace is ${st}"); return ErrorText(error: e.toString()); }, loading: () => Loader(), ); } }

TL;DR
The issue is that the endpoint in the .env file is incorrect. It should be `http://[MY IP]/v1` instead of `http://[MY IP]/80/v1`. Check the `_APP_OPTIONS_FORCE_HTTPS` env var for Appwrite, as it should be set to a value. Make sure there is nothing running between the app and Appwrite. Additionally, for nicer formatting, wrap code in backticks (`) and use three backticks for multiline code. Lastly, the correct spelling is Appwrite, not AppWrite. Solution: Update the endpoint in the .env file and check the `_APP
Drake
18 Apr, 2023, 17:29

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.

And, it's Appwrite, not AppWrite. 😛

Lastly, what's your code for the appwriteClientProvider? And do you have anything running in between your app and Appwrite?

disbold
18 Apr, 2023, 17:34

Ok that is good advice. I am just a beginner that is why.

disbold
18 Apr, 2023, 17:34
TypeScript
final appWriteClientProvider = Provider((ref) {
  Client client = Client();
  return client
      .setEndpoint(KAppWrite.baseEndPointUrl)
      .setProject(KAppWrite.projectId)
      .setSelfSigned(status: false);
});
Drake
18 Apr, 2023, 17:35

no worries! welcome!

disbold
18 Apr, 2023, 17:36

And there is noting in between the appwrite and the app. i am running from docker

Drake
18 Apr, 2023, 17:36

this looks mostly okay...what's your endpoint url?

Drake
18 Apr, 2023, 17:37

and what do you have set for the _APP_OPTIONS_FORCE_HTTPS env var for Appwrite?

disbold
18 Apr, 2023, 17:38

APP_WRITE_END_POINT=http://[MY IP]/80/v1 APP_WRITE_PROJECT_ID=6439bcdd4a97e9e4f785 APP_WRITE_DATABASE_ID=6439be5d13e3905d2cae APP_WRITE_USERS_COLLECTION_ID=643b112314651dfe809a APP_WRITE_EWEETS_COLLECTION_ID=643d33309b8f9a4e369f

disbold
18 Apr, 2023, 17:38

_APP_OPTIONS_FORCE_HTTPS i have not setted anything here

Drake
18 Apr, 2023, 17:50

http://[MY IP]/80/v1 doesn't look right. I think it should be http://[MY IP]/v1

Drake
18 Apr, 2023, 17:50

There should be some value set in the .env file

disbold
18 Apr, 2023, 18:01

Oh Thank you so much it worked, like you said the problem was the extra 80.

Drake
18 Apr, 2023, 18:19

[SOLVED] Unhandled Exception: WebSocketException

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