Skip to content

multicast_dns 0.2.0 not detecting mDNS packets #79772

Description

@biagiopietro

I'm trying to do a lookup of a specific service using mDNS but the client in Flutter returns nothing albeit the host (Android Device) received the correct packet from mDNS server (see Wireshark section).

Steps to Reproduce

  1. Create mDNS server (you can use the following code in Go. So you need to put the Go code in a file called main.go and run go get -u github.com/hashicorp/mdns && go run main.go, please make sure you're running that command in the same folder of your main.go. To make sure that the server is running, you can run curl -X GET 'http://localhost:8081/' and then you should receive an ok (see screenshot)
    image
package main

import (
	"fmt"
	"github.com/hashicorp/mdns"
	"os"
  "net/http"
)

func health(w http.ResponseWriter, r *http.Request) {
  fmt.Fprintf(w, "ok")
}

func main() {

	hostname, err := os.Hostname()

	if err != nil {
		panic(fmt.Sprintf("Error getting current hostname, description: %s", err.Error()))
	}

	info := []string{"mDNS get server"}

	service, err := mdns.NewMDNSService(hostname, "_test._tcp", "", "", 8080, nil, info)

	if err != nil {
		panic(fmt.Sprintf("Error while exporting the service, description: %s", err.Error()))
	}

	server, err := mdns.NewServer(&mdns.Config{Zone: service})

	if err != nil {
		panic(fmt.Sprintf("Error while setting the discover server up, description: %s", err.Error()))
	}

	defer server.Shutdown()
	
	http.HandleFunc("/", health)
	http.ListenAndServe(":8081",nil)
}
  1. To check if mDNS server is working you can run (OSX): dns-sd -B _test._tcp (Linux: sudo apt-get install avahi-deamonavahi-utils && avahi-browse -rt _test._tcp)
  2. Regarding flutter you can use:
import 'package:multicast_dns/multicast_dns.dart';
import 'dart:io' show Platform;

Future<void> main() async {
  const String name = '_test._tcp.local';
  MDnsClient client;
  if (Platform.isAndroid) {
     var factory = (dynamic host, int port,
         {bool reuseAddress, bool reusePort, int ttl}) {
       print("Hostname $host");
       print("Port ${port.toString()}");
       return RawDatagramSocket.bind(host, port, reuseAddress: true, reusePort: false, ttl: ttl);
     };
     client = MDnsClient(rawDatagramSocketFactory: factory);
   } else {
     client = MDnsClient();
  }
  // Start the client with default options.
  await client.start();

  // Get the PTR record for the service.
  await for (final PtrResourceRecord ptr in client
      .lookup<PtrResourceRecord>(ResourceRecordQuery.serverPointer(name))) {
    // Use the domainName from the PTR record to get the SRV record,
    // which will have the port and local hostname.
    // Note that duplicate messages may come through, especially if any
    // other mDNS queries are running elsewhere on the machine.
    await for (final SrvResourceRecord srv in client.lookup<SrvResourceRecord>(
        ResourceRecordQuery.service(ptr.domainName))) {
      // Domain name will be something like "[email protected]._dartobservatory._tcp.local"
      final String bundleId =
          ptr.domainName; //.substring(0, ptr.domainName.indexOf('@'));
      print('Dart observatory instance found at '
          '${srv.target}:${srv.port} for "$bundleId".');
    }
  }
  client.stop();

  print('Done.');
}
  1. Run flutter run -d <android-device>.

Expected results:
Something like Dart observatory instance found at...

Actual results:

I/ViewRootImpl(28364): jank_removeInvalidNode all the node in jank list is out of time
W/InputMethodManager(28364): startInputReason = 1
I/flutter (28364): Hostname 0.0.0.0
I/flutter (28364): Port 5353
V/AudioManager(28364): playSoundEffect   effectType: 0
V/AudioManager(28364): querySoundEffectsEnabled...
I/flutter (28364): Hostname InternetAddress('127.0.0.1', IPv4)
I/flutter (28364): Port 5353
I/flutter (28364): Hostname InternetAddress('192.168.2.1', IPv4)
I/flutter (28364): Port 5353
I/flutter (28364): Done.
Logs

flutter doctor -v

[✓] Flutter (Channel stable, 2.0.4, on Linux, locale en_US.UTF-8)
    • Flutter version 2.0.4 at /home/puma/snap/flutter/common/flutter
    • Framework revision b1395592de (4 days ago), 2021-04-01 14:25:01 -0700
    • Engine revision 2dce47073a
    • Dart version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /mnt/hd/Android/android-sdk-linux
    • Platform android-30, build-tools 29.0.2
    • Java binary at: /snap/android-studio/current/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Android Studio
    • Android Studio at /snap/android-studio/current/android-studio/
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /snap/android-studio/current/android-studio/
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (2 available)
    • ANE LX1 (mobile) • testAndroid • android-arm64  • Android 9 (API 28)
    • Chrome (web)     • chrome           • web-javascript • Google Chrome 89.0.4389.114

• No issues found!

flutter attach --verbose

[ +148 ms] executing: [/home/puma/snap/flutter/common/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[  +72 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] b1395592de68cc8ac4522094ae59956dd21a91db
[   +1 ms] executing: [/home/puma/snap/flutter/common/flutter/] git tag --points-at b1395592de68cc8ac4522094ae59956dd21a91db
[  +24 ms] Exit code 0 from: git tag --points-at b1395592de68cc8ac4522094ae59956dd21a91db
[        ] 2.0.4
[  +79 ms] executing: [/home/puma/snap/flutter/common/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[   +8 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [/home/puma/snap/flutter/common/flutter/] git ls-remote --get-url origin
[   +9 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[ +114 ms] executing: [/home/puma/snap/flutter/common/flutter/] git rev-parse --abbrev-ref HEAD
[  +10 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[ +151 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[   +3 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[  +12 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +154 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[ +123 ms] executing: /mnt/hd/Android/android-sdk-linux/platform-tools/adb devices -l
[  +68 ms] List of devices attached
           testAndroid       device usb:2-1.1 product:ANE-LX1 model:ANE_LX1 device:HWANE transport_id:1
[ +102 ms] /mnt/hd/Android/android-sdk-linux/platform-tools/adb -s testAndroid shell getprop
[ +163 ms] Waiting for a connection from Flutter on ANE LX1...
[ +134 ms] Observatory URL on device: http://127.0.0.1:36421/LB5gpdiwoUU=/
[   +2 ms] executing: /mnt/hd/Android/android-sdk-linux/platform-tools/adb -s testAndroid forward tcp:0 tcp:36421
[  +15 ms] 45003
[   +1 ms] Forwarded host port 45003 to device port 36421 for Observatory
[   +9 ms] Connecting to service protocol: http://127.0.0.1:45003/LB5gpdiwoUU=/
[ +186 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:45003/LB5gpdiwoUU=/.
[ +404 ms] Warning: Failed to start DDS: JSON-RPC error 100: Feature is disabled data: {details: A DDS instance is already connected at http://127.0.0.1:32821/rrJgFvQe3xQ=/., request: {jsonrpc: 2.0, method: _yieldControlToDDS, id: 8, params: {uri:
http://127.0.0.1:37321/2bciKM125Ng=/}}}
[  +55 ms] Successfully connected to service protocol: http://127.0.0.1:45003/LB5gpdiwoUU=/
[   +2 ms] executing: /mnt/hd/Android/android-sdk-linux/platform-tools/adb -s testAndroid shell -x logcat -v time -t 1
[  +84 ms] --------- beginning of main
           04-05 14:15:50.212 I/TrafficMonitor( 1273): gettimer:interval=2000
[ +955 ms] DevFS: Creating new filesystem on the device (null)
[  +18 ms] DevFS: Creating failed. Destroying and trying again
[   +1 ms] DevFS: Deleting filesystem on the device (null)
[  +34 ms] DevFS: Deleted filesystem on the device (null)
[  +15 ms] DevFS: Created new filesystem on the device (file:///data/user/0/com.example.test_mdns_client/code_cache/test_mdns_clientJAQOEZ/test_mdns_client/)
[  +10 ms] Updating assets
[ +299 ms] Syncing files to device ANE LX1...
[   +4 ms] <- reset
[        ] Compiling dart to kernel with 0 updated files
[  +17 ms] /home/puma/snap/flutter/common/flutter/bin/cache/dart-sdk/bin/dart --disable-dart-dev /home/puma/snap/flutter/common/flutter/bin/cache/artifacts/engine/linux-x64/frontend_server.dart.snapshot --sdk-root
/home/puma/snap/flutter/common/flutter/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --incremental --target=flutter --debugger-module-names --experimental-emit-debug-metadata --output-dill /tmp/flutter_tools.FDFYPD/flutter_tool.JBRCDK/app.dill
--packages /home/puma/StudioProjects/test_mdns_client/.dart_tool/package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --filesystem-scheme org-dartlang-root --initialize-from-dill
build/cache.dill.track.dill
[  +12 ms] <- compile package:test_mdns_client/main.dart

pubspec.yaml

name: test_mdns_client
description: A new Flutter project.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  intl: ^0.15.7
  multicast_dns: any

  cupertino_icons: ^1.0.2

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

Wireshark

Source	        Destination	Protocol	Length	Info
192.168.2.1	224.0.0.251	MDNS		76	Standard query 0x0000 PTR _test._tcp.local, "QM" question
192.168.2.4	192.168.2.1	MDNS		180	Standard query response 0x0000 PTR puma._test._tcp.local SRV 10 1 8080 puma A 127.0.1.1 TXT

Where:

  • 192.168.2.1 is testAndroid device;
  • 192.168.2.4 is the device where mDNS server is running on.

Thanks in advance for your help!!!

Activity

  1. TahaTesser commented on Apr 6, 2021

    @TahaTesser
    Contributor

    Hi @biagiopietro
    I am not familiar with go but I just installed go and tried your command, i get the following error

    tahatesser@Tahas-MBP AndroidStudioProjects % go get github.com/hashicorp/mdns && go run main.go
    stat main.go: no such file or directory
    tahatesser@Tahas-MBP AndroidStudioProjects % ls
    tahatesser@Tahas-MBP AndroidStudioProjects % 
    

    version

    tahatesser@Tahas-MBP AndroidStudioProjects % go version
    go version go1.16.3 darwin/amd64
    tahatesser@Tahas-MBP AndroidStudioProjects % 
    

    Can you please update the reproducible steps
    Thank you

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 6, 2021
  3. biagiopietro commented on Apr 6, 2021

    @biagiopietro
    Author

    Hello @TahaTesser,
    You need to put the Go code in a file called main.go and run go run main.go, please make sure you're running that command in the same folder of your main.go. To make sure that the server is running, you can run curl -X GET 'http://localhost:8081/' and then you should receive an ok (see screenshot)
    image
    Please let me know how can I help (reproducible steps updated)

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 6, 2021
  5. TahaTesser commented on Apr 7, 2021

    @TahaTesser
    Contributor

    @biagiopietro
    I did the same steps, created a folder and main.go file and copied the Go code and ran the command, I get

    tahatesser@Tahas-MBP test_go % ls
    main.go
    tahatesser@Tahas-MBP test_go % go get -u github.com/hashicorp/mdns && go run main.go
    main.go:5:2: no required module provides package github.com/hashicorp/mdns: go.mod file not found in current directory or any parent directory; see 'go help modules'
    tahatesser@Tahas-MBP test_go % 
    

    Edit:
    Tried on a different computer, same error

    image

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 7, 2021
  7. biagiopietro commented on Apr 7, 2021

    @biagiopietro
    Author

    @TahaTesser really weird behavior. 😞 I've tried also on OSX and Ubuntu machines without any issue.
    Could you please run go mod init main in the same location of your main.go.
    It will generate a go.mod file and inside you should put the following line require github.com/hashicorp/mdns v1.0.3 (after module main).
    Once you are done please save the file and run again go run main.go (see screenshot for more details)
    image

  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 7, 2021
  9. biagiopietro commented on Apr 7, 2021

    @biagiopietro
    Author

    I saw that you are using Go version go1.16.3 so I upgraded also to that version and I tried the steps described before and they worked for me

  10. TahaTesser commented on Apr 8, 2021

    @TahaTesser
    Contributor

    Hi @biagiopietro
    Thanks for the details, go mod init main did the trick and main.go is running and curl -X GET 'http://localhost:8081/' is returning ok

    DNS - main.go preview

    image
    image (1)

    logs
    Launching lib/main.dart on RMX2001 in debug mode...
    ✓ Built build/app/outputs/flutter-apk/app-debug.apk.
    Connecting to VM Service at ws://127.0.0.1:45587/dDUB8u2-dhU=/ws
    I/flutter (15328): Hostname 0.0.0.0
    I/flutter (15328): Port 5353
    I/flutter (15328): Hostname InternetAddress('127.0.0.1', IPv4)
    I/flutter (15328): Port 5353
    I/flutter (15328): Hostname InternetAddress('192.168.0.159', IPv4)
    I/flutter (15328): Port 5353
    D/ColorViewRootUtil(15328): nav gesture mode swipeFromBottom ignore false downY 1242 mScreenHeight 2400 mScreenWidth 1080 mStatusBarHeight 54 globalScale 1.125 nav mode 3 event MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=432.0, y[0]=1242.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=291572, downTime=291572, deviceId=3, source=0x1002, displayId=0 } rotation 0
    I/flutter (15328): Done.
    I/SurfaceView(15328): 229261539 visibleChanged:true -> SurfaceHolder.Callback.surfaceDestroyed
    D/Surface (15328): Surface::disconnect(this=0x70d00e6000,api=1)
    D/ViewRootImpl(15328): setSurfaceViewCreated, created:false
    D/Surface (15328): Surface::disconnect(this=0x70d00e6000,api=-1)
    D/SurfaceView(15328): updateScreenMode w:0 h:0 ViewRoot w:1080 h:2400
    D/SurfaceView(15328): try to resquest 90Hz
    D/ViewRootImpl(15328): set screen refresh mode 0 due to SurfaceView-229261539
    I/Choreographer(15328): Skipped 5 frames!  The application may be doing too much work on its main thread.
    I/GED     (15328): ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 27, oppidx_max 27, oppidx_min 0
    D/Surface (15328): Surface::disconnect(this=0x70d00e4000,api=1)
    V/PhoneWindow(15328): DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@89f9b74, this = DecorView@9560761[MainActivity]
    dependencies:
      flutter:
        sdk: flutter
      cupertino_icons: ^1.0.2
      multicast_dns: ^0.2.2 
    flutter doctor -v
    taha@taha-Lenovo-ideapad-510S-14IKB:~/AndroidStudioProjects$ fsd
    [✓] Flutter (Channel stable, 2.0.4, on Linux, locale en_IN)
        • Flutter version 2.0.4 at /home/taha/Code/flutter_stable
        • Framework revision b1395592de (6 days ago), 2021-04-01 14:25:01 -0700
        • Engine revision 2dce47073a
        • Dart version 2.12.2
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /home/taha/Code/SDK
        • Platform android-30, build-tools 30.0.3
        • ANDROID_HOME = /home/taha/Code/SDK
        • Java binary at: /home/taha/Code/android-studio/jre/bin/java
        • Java version OpenJDK Runtime Environment (build
          1.8.0_242-release-1644-b3-6222593)
        • All Android licenses accepted.
    [✓] Chrome - develop for the web
        • Chrome at google-chrome
    [✓] Linux toolchain - develop for Linux desktop
        • clang version 10.0.0-4ubuntu1
        • cmake version 3.16.3
        • ninja version 1.10.0
        • pkg-config version 0.29.1
    [!] Android Studio (not installed)
        • Android Studio not found; download from
          https://developer.android.com/studio/index.html
          (or visit https://flutter.dev/docs/get-started/install/linux#android-setup
          for detailed instructions).
    [✓] Connected device (3 available)
        • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 10 (API 29)
        • Linux (desktop)  • linux            • linux-x64      • Linux
        • Chrome (web)     • chrome           • web-javascript • Google Chrome
          89.0.4389.90
    ! Doctor found issues in 1 category.
    taha@taha-Lenovo-ideapad-510S-14IKB:~/AndroidStudioProjects$ 

    Thanks for filing the issue

  11. added
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Apr 8, 2021
  12. 28 remaining items

  13. mbalmer commented on Feb 25, 2024

    @mbalmer

    This is still not working properly as of today. A mDNS resolver on my device shows me what I am looking for, but multicast_dns usually does not resolve anything. Sometimes it does....

  14. biagiopietro commented on May 2, 2024

    @biagiopietro
    Author

    Hello everyone,
    My apologies for the long absence on this.
    I will try to follow up again, from what I checked looks like that there are some edge cases on network level that are not handled properly.
    I need to dust off again wireshark and have a deep look.

  15. biagiopietro commented on May 9, 2024

    @biagiopietro
    Author

    Hi @MarcelKr ,@mbalmer, @exaby73
    It took a while to investigate a possible solution, I put findings and 2 proposals in the following PR (I just applied one)

    Please I'm not an expert and I would like to have also your eyes on it.

    (Having a confirmation that it fixes also in your case is really appreciated)

  16. MarcelKr commented on May 13, 2024

    @MarcelKr

    Hey @biagiopietro. Thanks for taking the time in attempting to fix this, that's really cool! However I'm absolutely not confident in making any judgement on the PR since I'm neither an expert in dart (which would probably not be the big issue here) nor in the details one needs to know about networking to add profound statements unfortunately :/

  17. added a commit that references this issue on Jun 25, 2024
  18. added a commit that references this issue on Jun 25, 2024
  19. github-actions commented on Jul 8, 2024

    @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.

  20. locked as resolved and limited conversation to collaborators on Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 2.0Found to occur in 2.0has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: multicast_dnsThe mdns packagepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions