Search code examples
flutterdartsignalrsignalr.clientdart-null-safety

Problem using signalr for chat application flutter


I had made a whole chat application using signalr as a socket with the online and offline facility. I am facing a few problems,

  • Signalr connection is always time out after some time, to overcome that I had condition if hubconnection is not connected then create new hubconnection (onResume app), but still it get hubconnection._callback got increased when sending message and not moving to server side socket. Again need to refresh whole app.

Can someone tell me whether this is problem because there are lot of operations going on and so signalr loses its connection as flutter is single thread and it cannot handle much? or should I use Isolate or inherit widget.

Summary problem:

I cannot send message in chat after sometime. It stores all message in hubconnection._callback and not going for server.

Is anything better solution to keep alive in both Android+iOS.

I had used https://pub.dev/packages/signalr_netcore package.

Please do not mention about firebase.

Any other logic suggestion is appreciable. Thank you.


Solution

  • I've been using a different package, https://pub.dev/packages/signalr_core, which works fine without any particular issues what I have observed at the moment.

    I'm only running about 10 listeners simultaneously, not sure if that is more or less than you. In the package I'm running you can establish connection with automatic reconnect. It looks like this:

    HubConnectionBuilder().withAutomaticReconnect().withUrl(....)
    

    It seems like your package have the same functionality... Have you tried that?