Hi all,
Looking for some advice on whether there's a better way to handle client/server communication as my current approach feels very messy.
In essence, I need a method to open a connection from my Flutter app to a device over TCP/IP connection, and pass simple commands and data strings back and forth.
My first basic testing as I built my GUI just used http. That works reliably, but there's a lot of unnecessary overhead there when you just want to pass simple commands, and now the GUI side is built I've started the work to implement WebSockets for the communication, using the package IOWebSocketChannel, as described in the Flutter Cookbook:
https://flutter.dev/docs/cookbook/networking/web-sockets
Basic functional tests worked ok, but I've hit a stumbling block in that it seems that error handling is lacking or non-existent with this package. Specifically if the remote webSocket server is offline for any reason, IOWebSocketChannel.connect silently fails. It doesn't throw an exception as documented, still returns a socket, and there doesn't appear to be any way to detect whether you actually have a working connection or not.
I can see this has been reported a few times in the past, but so far can't find any workaround:
For now I'm using http to test that the remote system is available, and switching to WebSockets afterwards, trusting that the other error handling within this package works.
Does anybody have a better idea?