sendReceive method
Implementation
@override
Future<Uint8List?> sendReceive(String epName, Uint8List data) async {
try {
print("Connecting to " + hostname + "/" + epName);
final response = await client
.post(
Uri.http(
hostname,
"/" + epName,
),
headers: headers,
body: data)
.timeout(timeout)
.onError((error, stackTrace) {
print("onError");
print(error.toString());
print(stackTrace.toString());
return Future.error(error!);
});
_updateCookie(response);
if (response.statusCode == 200) {
print('Connection successful');
// client.close();
final Uint8List body_bytes = response.bodyBytes;
return body_bytes;
} else {
print('Connection failed – HTTP-Status ${response.statusCode}');
throw Future.error(Exception("ESP Device doesn't repond. HTTP-Status ${response.statusCode}"));
}
} catch (e) {
throw StateError('StateError in transport_http.dart – Connection error (${e.runtimeType.toString()})' + e.toString());
}
}