Repository navigation
multicast_dns 0.2.0 not detecting mDNS packets #79772
Copy link
Copy link
Closed
flutter/packages
#6700Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfound in release: 2.0Found to occur in 2.0Found to occur in 2.0has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: multicast_dnsThe mdns packageThe mdns packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Description
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
- Create
mDNS server(you can use the following code inGo. So you need to put theGocode in a file calledmain.goand rungo get -u github.com/hashicorp/mdns && go run main.go, please make sure you're running that command in the same folder of yourmain.go. To make sure that the server is running, you can runcurl -X GET 'http://localhost:8081/'and then you should receive anok(see screenshot)

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)
}- To check if
mDNS serveris working you can run (OSX):dns-sd -B _test._tcp(Linux:sudo apt-get install avahi-deamonavahi-utils && avahi-browse -rt _test._tcp) - 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.');
}- 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.1istestAndroiddevice;192.168.2.4is the device where mDNS server is running on.
Thanks in advance for your help!!!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfound in release: 2.0Found to occur in 2.0Found to occur in 2.0has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: multicast_dnsThe mdns packageThe mdns packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Activity
TahaTesser commentedon Apr 6, 2021
Hi @biagiopietro
I am not familiar with
gobut I just installedgoand tried your command, i get the following errorversion
Can you please update the reproducible steps
Thank you
biagiopietro commentedon Apr 6, 2021
Hello @TahaTesser,

You need to put the
Gocode in a file calledmain.goand rungo run main.go, please make sure you're running that command in the same folder of yourmain.go. To make sure that the server is running, you can runcurl -X GET 'http://localhost:8081/'and then you should receive anok(see screenshot)Please let me know how can I help (reproducible steps updated)
TahaTesser commentedon Apr 7, 2021
@biagiopietro
I did the same steps, created a folder and
main.gofile and copied theGocode and ran the command, I getEdit:
Tried on a different computer, same error
biagiopietro commentedon Apr 7, 2021
@TahaTesser really weird behavior. 😞 I've tried also on

OSXandUbuntumachines without any issue.Could you please run
go mod init mainin the same location of yourmain.go.It will generate a
go.modfile and inside you should put the following linerequire github.com/hashicorp/mdns v1.0.3(aftermodule main).Once you are done please save the file and run again
go run main.go(see screenshot for more details)biagiopietro commentedon Apr 7, 2021
I saw that you are using
Go version go1.16.3so I upgraded also to that version and I tried the steps described before and they worked for meTahaTesser commentedon Apr 8, 2021
Hi @biagiopietro
Thanks for the details,
go mod init maindid the trick and main.go is running andcurl -X GET 'http://localhost:8081/'is returningokDNS - main.go preview
logs
flutter doctor -v
Thanks for filing the issue
28 remaining items
mbalmer commentedon Feb 25, 2024
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....
biagiopietro commentedon May 2, 2024
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.
biagiopietro commentedon May 9, 2024
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)
MarcelKr commentedon May 13, 2024
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 :/
[multicast_dns] Optimized Socket Binding: Always bind to 0.0.0.0 for …
b4d79b5 [multicast_dns] Optimized Socket Binding: Always bind to 0.0.…
Roll Packages from 711b4ac to 03f5f6d (21 revisions) (#150779)
github-actions commentedon Jul 8, 2024
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 -vand a minimal reproduction of the issue.