Skip to content

mDNS discovery works on iOS simulator but not on real device (SocketException errno = 65) #177307

@superwebarmy

Description

@superwebarmy

I’m using Flutter’s multicast_dns package to discover Android TVs on the local network using mDNS. The code works perfectly on the iOS simulator, but fails on a real iPhone with the following error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: SocketException: Send failed (OS Error: No route to host, errno = 65), address = 0.0.0.0, port = 5353
#0      _NativeSocket.send (dart:io-patch/socket_patch.dart:1521:34)
#1      _RawDatagramSocket.send (dart:io-patch/socket_patch.dart:3078:15)
#2      MDnsClient.lookup (package:multicast_dns/multicast_dns.dart:227:22)
Future<void> search() async {
  const String name = '_androidtvremote2._tcp';
  final MDnsClient client = MDnsClient();

  try {
    await client.start();

    await for (final PtrResourceRecord ptr in client
        .lookup<PtrResourceRecord>(ResourceRecordQuery.serverPointer(name))) {
      final fullName = ptr.domainName;
      final friendlyName = fullName.split('.')[0];

      await for (final SrvResourceRecord srv in client
          .lookup<SrvResourceRecord>(
            ResourceRecordQuery.service(ptr.domainName),
          )) {
        final host = srv.target;
        final port = srv.port;

        await for (final IPAddressResourceRecord addr in client
            .lookup<IPAddressResourceRecord>(
              ResourceRecordQuery.addressIPv4(host),
            )) {
          final ip = addr.address.address;
          print('Found $friendlyName at $ip:$port');
        }
      }
    }

    client.stop();
  } catch (error) {
    print(error);
  }
}

I’ve already done the following:

  • Added NSLocalNetworkUsageDescription in Info.plist.

  • Added NSBonjourServices with _androidtvremote2._tcp.

  • Local network permission is ON in iOS Settings.

  • Works fine on iOS simulator and Android devices.

  • Both iPhone and Android TV are on the same Wi-Fi.

Despite all that, it always throws SocketException (OS Error: No route to host, errno = 65) on a real iPhone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in triagePresently being triaged by the triage teamwaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions