goto-bus-stop / dart-event-source

W3C EventSource client implementation for Dart
MIT License
9 stars 12 forks source link

How to handle connection timed out error #15

Open kakopappa opened 4 years ago

kakopappa commented 4 years ago

Hi guys,

final events = EventSource(Uri.parse(sseEndpointUrl), initialReconnectDelay: new Duration(seconds:1));

try {
    events.events.listen((MessageEvent message) {
      print('SSE event: ${message.data}');
    }).onError((error) => {
      print('SSE event error: $error')
    });
} on SocketException catch(error) {
    print('$error');          
}

E/flutter (30879): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.1.100, port = 53342 E/flutter (30879):

This throws SocketException when the server is unavailable, it doesn't seem to goto onError or try catch. any idea how to handle it?

goto-bus-stop commented 3 years ago

could be a bug. i'm not using dart/flutter for anything lately but if you or anyone wants to look into this and maybe send a PR i'd review it.

mikezander commented 3 months ago

Did you ever find a solution to this? I had to put in a connection listener as a workaround.

kakopappa commented 3 months ago

Copied the code to my project and change the code to reconnect on disconnect