A Dart package to do service discovery over multicast DNS (mDNS), Bonjour, and Avahi.
To use this package, add multicast_dns
as a
dependency in your pubspec.yaml file.
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.
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.');
}
Add this to your package's pubspec.yaml file:
dependencies:
multicast_dns: ^0.1.0+1
You can install packages from the command line:
with pub:
$ pub get
Alternatively, your editor might support pub get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:multicast_dns/multicast_dns.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.1.0+1 | Jan 24, 2019 |
|
|
0.1.0 | Jan 24, 2019 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
53
|
Health:
Code health derived from static analysis.
[more]
|
0
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
62
|
Overall:
Weighted score of the above.
[more]
|
39
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms:
Error(s) prevent platform classification:
Fix dependencies in
pubspec.yaml
.
Fix dependencies in pubspec.yaml
.
Running pub upgrade
failed with the following output:
ERR: The current Dart SDK version is 2.1.0.
Because multicast_dns requires SDK version >=2.1.1-dev.2.0 <3.0.0, version solving failed.
Fix platform conflicts. (-20 points)
Error(s) prevent platform classification:
Fix dependencies in pubspec.yaml
.
Make sure dartdoc
successfully runs on your package's source files. (-10 points)
Dependencies were not resolved.
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 |