We don't seem to check if the socket is bound (send's return value is typically ignored, and it's always -1?), but perhaps this is okay since we have retries anyway. Should we ignore any SocketExceptions thrown by send as well then?
Once this issue is fixed I need to remember to test if the previously bound socket is still usable, or if we need to re-bind after some downtime. Need to think about error handling for observe as well, on re-bind...
Example, turning my wifi off during this loop (testing what happens if I drop off a shaky network temporarily):
FutureOr<void> main() async {
final conf = CoapConfig();
final uri = Uri(
scheme: 'coap',
host: 'californium.eclipseprojects.io',
port: conf.defaultPort,
);
final client = CoapClient(uri, conf);
try {
for (var i = 0; i < 10; i++) {
print('Sending request $i');
final resp = await client.get('test');
if (resp.code != CoapCode.content) {
print('Request failed!');
}
await Future<void>.delayed(const Duration(seconds: 5));
}
} on Exception catch (e) {
print('CoAP encountered an exception: $e');
}
client.close();
}
We don't seem to check if the socket is bound (
send
's return value is typically ignored, and it's always -1?), but perhaps this is okay since we have retries anyway. Should we ignore anySocketExceptions
thrown bysend
as well then?Once this issue is fixed I need to remember to test if the previously bound socket is still usable, or if we need to re-bind after some downtime. Need to think about error handling for observe as well, on re-bind...
Example, turning my wifi off during this loop (testing what happens if I drop off a shaky network temporarily):