multicast_dns 0.2.2

Multicast DNS package #

pub package

A Dart package to do service discovery over multicast DNS (mDNS), Bonjour, and Avahi.

Usage #

To use this package, add multicast_dns as a dependency in your pubspec.yaml file.

Example #

Import the library via

import 'package:multicast_dns/multicast_dns.dart';

Then use the MDnsClient Dart class in your code. To see how this is done, check out the example app or the sample implementations in the bin directory.

0.2.2 #

  • Fixes parsing of TXT records. Continues parsing on non-utf8 strings.

0.2.1 #

  • Fixes the handling of packets containing non-utf8 strings.

0.2.0 #

  • Allow configuration of the port and address the mdns query is performed on.

0.1.1 #

  • Fixes flutter/issue/31854 where decodeMDnsResponse advanced to incorrect code points and ignored some records.

0.1.0 #

  • Initial Open Source release.
  • Migrates the dartino-sdk's mDNS client to Dart 2.0 and Flutter's analysis rules
  • Breaks from original Dartino code, as it does not use native libraries for macOS and overhauls the ResourceRecord class.


// Copyright 2018, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Example script to illustrate how to use the mdns package to discover the port
// of a Dart observatory over mDNS.

import 'package:multicast_dns/multicast_dns.dart';

Future<void> main() async {
  // Parse the command line arguments.

  const String name = '_dartobservatory._tcp.local';
  final MDnsClient client = MDnsClient();
  // Start the client with default options.
  await client.start();

  // Get the PTR recod for the service.
  await for (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 (SrvResourceRecord srv in client.lookup<SrvResourceRecord>(
        ResourceRecordQuery.service(ptr.domainName))) {
      // Domain name will be something like "io.flutter.example@some-iphone.local._dartobservatory._tcp.local"
      final String bundleId =
          ptr.domainName; //.substring(0, ptr.domainName.indexOf('@'));
      print('Dart observatory instance found at '
          '${}:${srv.port} for "$bundleId".');


Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  multicast_dns: ^0.2.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:multicast_dns/multicast_dns.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Maintenance suggestions

The package description is too short. (-8 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.1-dev.2.0 <3.0.0
meta ^1.1.6 1.1.8
Dev dependencies
mockito ^4.1.0
test ^1.3.4