Repository: flutter
Issue: multicast_dns client is not discovering service on the network on Android devices
Labels: platform-android,package,p: multicast_dns,has reproducible steps,P2,team-android,triaged-android,found in release: 3.24,found in release: 3.26

### Steps to reproduce

1. Run the sample flutter code give below on a real Android Device
2. Run the python code on a computer (it will Register a sample service on the network)
3. Make sure computer running python code and the android device are on same network

### Expected results

The service on the network should be discovered and its ip should be displayed

### Actual results

- lookup function is not returning anything on a physical android device : tested on Samsung (Android 12) and OnePlus(Android 14)),
- works on iOS simulator and MacOS, haven't tried it on physical iOS device 


### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:multicast_dns/multicast_dns.dart';
import 'dart:developer' as developer;

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
               colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, });


  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Set<String> _hosts = <String>{};
  final String name = 'sample._http._tcp.local';

  Future<void> _incrementCounter() async {

  //TODO: use this on android
  //  final MDnsClient client = MDnsClient(rawDatagramSocketFactory:
  //  (dynamic host, int port,
  //      {bool? reuseAddress, bool? reusePort, int? ttl}) {
  //      return RawDatagramSocket.bind(host, port,
  //    reuseAddress: true, reusePort: false, ttl: ttl!);
  //  });

   //TODO: use this on iOS
   MDnsClient client = MDnsClient();

    await client.start();
    developer.log('started');
    client.lookup<IPAddressResourceRecord>(ResourceRecordQuery.addressIPv4(name)).
        listen((record){
          developer.log('found something $record');
            setState(() {
            _hosts.add(record.address.address);
            });
        }
       ).onDone((){
            client.stop();
            developer.log('stopped');
       });
    
      }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'InternetAddress of the sample service on the network ',
            ),
            Text(
              '$_hosts',
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

```

```python
#pip install zeroconf
from zeroconf import ServiceInfo, Zeroconf
import socket

def main():
    # Get your local IP address
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("8.8.8.8", 80))
    local_ip = s.getsockname()[0]
    s.close()

    info = ServiceInfo(
        "_http._tcp.local.",
        "sample._http._tcp.local.",
        addresses=[socket.inet_aton(local_ip)],
        port=8000,
        properties={"path": "/"},
    )

    zeroconf = Zeroconf()
    zeroconf.register_service(info)

    try:
        input("Press enter to exit...\n\n")
    finally:
        zeroconf.unregister_service(info)
        zeroconf.close()

if __name__ == "__main__":
    main()
```



</details>


### Screenshots or Video

_No response_

### Logs

<details open><summary>Logs</summary>

```console
Launching lib/main.dart on SM M215F in debug mode...
✓ Built build/app/outputs/flutter-apk/app-debug.apk
I/ViewRootImpl@9e069d2[MainActivity](17642): [DP] cancelDraw null isViewVisible: true
D/InsetsSourceConsumer(17642): ensureControlAlpha: for ITYPE_NAVIGATION_BAR on com.example.mdns_search/com.example.mdns_search.MainActivity
D/InsetsSourceConsumer(17642): ensureControlAlpha: for ITYPE_STATUS_BAR on com.example.mdns_search/com.example.mdns_search.MainActivity
I/ViewRootImpl@9e069d2[MainActivity](17642): [DP] cancelDraw null isViewVisible: true
[log] started
[log] stopped
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.24.2, on macOS 14.6.1 23G93 darwin-arm64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.93.1)
[✓] Connected device (5 available)
[✓] Network resources

• No issues found!
```

</details>