multicast_dns 0.2.0

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/mdns_client.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.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.

example/main.dart

// 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';

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.target}:${srv.port} for "$bundleId".');
    }
  }
  client.stop();

  print('Done.');
}

Use this package as a library

1. Depend on it

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


dependencies:
  multicast_dns: ^0.2.0

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
93
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
92
Overall:
Weighted score of the above. [more]
95
Learn more about scoring.

We analyzed this package on Sep 19, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:multicast_dns/multicast_dns.dart with components: io.

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.

Dependencies

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