I want to send data to esp32 via WiFi using UDP, but it'S returning 0 bytes (as 0 bytes sent)
For Esp32 I tried with another device (different mobile app), and it's working fine.(Esp32 is OK)
Here is my code for sending data:
Future<void> sendMessage(String message) async {
try {
sender = await UDP.bind(
Endpoint.any(port: const Port(4210)),
);
final data = Uint8List.fromList(utf8.encode(message));
final endpoint = Endpoint.unicast(
InternetAddress("192.168.4.1"),
port: const Port(3333),
);
final sent = await sender!.send(data, endpoint);
print("Sent $sent bytes: '$message'");
} catch (e) {
print('Error sending UDP message: $e');
}
}
And here are my manifest persmissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Additionaly anything more needed?
What could be the reason for this issue?
I tried in different mobile apps, that works fine, also tried in Linux terminal using netcat.
dart:io? See: api.flutter.dev/flutter/dart-io/RawDatagramSocket-class.html