Skip to content

Teach flutter_tools how to use mDNS to find the iOS observatory port #23164

Description

@dnfield

flutter-team-archive/engine#6533 added the ability to have iOS apps advertise the Dart observatory port over mDNS. The following command on macOS can display that information:

dns-sd -Z _dartobservatory._tcp

which has output similar to the following:

Browsing for _dartobservatory._tcp
DATE: ---Tue 16 Oct 2018---
11:00:09.974  ...STARTING...

; To direct clients to browse a different domain, substitute that domain in place of '@'
lb._dns-sd._udp                                 PTR     @

; In the list of services below, the SRV records will typically reference dot-local Multicast DNS names.
; When transferring this zone file data to your unicast DNS server, you'll need to replace those dot-local
; names with the correct fully-qualified (unicast) domain name of the target host offering the service.

_dartobservatory._tcp                           PTR     com\.example\.iosTestMod@dans-iphone\.local._dartobservatory._tcp
com\.example\.iosTestMod@dans-iphone\.local._dartobservatory._tcp SRV     0 0 49198 Dans-iPhone.local. ; Replace with unicast FQDN of target host
com\.example\.iosTestMod@dans-iphone\.local._dartobservatory._tcp TXT     ""

indicating the observatory port is running on 49198 from the SRV record. Running flutter attach --debug-port 49198 will successfully attach to that observatory port.

Unfortunately, dns-sd is not suitable for scripting (it never "finishes" processing, the output and command flags are explicitly not guaranteed), and we'd like to avoid adding more Ruby/Python/etc. scripts to support this.

Writing the mDNS query in Dart (particularly on macOS) is currently blocked by dart-lang/sdk#34799. A patch has been created, and using that source I've been able to successfully query the service using Dart on macOS.

Once that lands, we should be able to either implement mDNS in the Dart SDK (e.g. in dart:io), or at least have a simple client in the flutter_tools package that can discover the port automatically for flutter attach without any additional steps.

/cc @matthew-carroll @tvolkert @cbracken

Activity

  1. self-assigned this
    on Oct 16, 2018
  2. added
    platform-iosiOS applications specifically
    toolAffects the "flutter" command-line tool. See also t: labels.
    platform-macosBuilding on or for macOS specifically
    on Oct 16, 2018
  3. added this to the bucket11 milestone on Oct 16, 2018
  4. dnfield commented on Oct 18, 2018

    @dnfield
    ContributorAuthor

    Once flutter/packages#7 lands, we should be able to consume it in flutter_tools. From there it should be pretty straightforward.

  5. Hixie commented on Nov 21, 2018

    @Hixie
    Contributor

    Moving to bucket12 due to code freeze.

  6. modified the milestones: bucket11, bucket12 on Nov 21, 2018
  7. dnfield commented on Dec 19, 2018

    @dnfield
    ContributorAuthor

    This will require some changes upstream in Dart - I'm working on those, but it will take into January to get to it.

  8. DanTup commented on Dec 19, 2018

    @DanTup
    Contributor

    Is this iOS-only, or will it help Android? If Android, will it remove the reliance on logcat entirely? #25455 shows a device where logcat just stops streaming anything towards the end of boot, which means Flutter is never able to get the VM port (and I'm out of ideas for debugging!).

  9. matthew-carroll commented on Dec 19, 2018

    @matthew-carroll
    Contributor

    @DanTup Android should be able to utilize ADB directly via Intents which is much simpler than this iOS solution. I've been waiting for the iOS side to finish before worrying about Android because the Android path seems highly confident, whereas the iOS approach has changed a number of times and is still in flux.

  10. 1 remaining item

  11. dnfield commented on Jan 16, 2019

    @dnfield
    ContributorAuthor
  12. modified the milestones: February 2019, on Feb 6, 2019
  13. dnfield commented on Feb 6, 2019

    @dnfield
    ContributorAuthor

    This is waiting for Dart to catch up in google3. Updating milestone to March.

  14. modified the milestones: , March 2019 on Feb 6, 2019
  15. jonahwilliams commented on Feb 15, 2019

    @jonahwilliams
    Contributor

    I believe this landed, closing!

  16. jonahwilliams commented on Feb 15, 2019

    @jonahwilliams
    Contributor

    My bad!

  17. ventureli commented on May 21, 2020

    @ventureli

    The mDNS query for an attached iOS device failed. It may be necessary to disable the "Personal Hotspot" on the device, and to ensure that the "Disable unless needed" setting is unchecked under System Preferences > Network > iPhone USB. See #46698 for details.
    Waiting for a connection from Flutter on iPhone 11 Pro Max...

    I use simulator always get this message,what's wrong?

  18. github-actions commented on Aug 21, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  19. locked as resolved and limited conversation to collaborators on Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

dependency: dartDart team may need to help usplatform-iosiOS applications specificallyplatform-macosBuilding on or for macOS specificallytoolAffects the "flutter" command-line tool. See also t: labels.waiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions