| Index: pkg/mdns/bin/mdns-sd.dart
|
| diff --git a/pkg/mdns/bin/mdns-sd.dart b/pkg/mdns/bin/mdns-sd.dart
|
| index 1357aa71e43f9ac5851a244f219300699be5fbc5..6310626ff6e477f49e9d4be7ce5a5d76e3587489 100644
|
| --- a/pkg/mdns/bin/mdns-sd.dart
|
| +++ b/pkg/mdns/bin/mdns-sd.dart
|
| @@ -5,25 +5,35 @@
|
| // Example script to illustrate how to use the mdns package to discover services
|
| // on the local network.
|
|
|
| -import 'mdns.dart';
|
| +import 'package:args/args.dart';
|
| +
|
| +import '../lib/mdns.dart';
|
|
|
| main(List<String> args) async {
|
| - if (args.length != 1) {
|
| + // Parse the command line arguments.
|
| + var parser = new ArgParser();
|
| + parser.addOption('timeout', abbr: 't', defaultsTo: '5');
|
| + var arguments = parser.parse(args);
|
| +
|
| + if (arguments.rest.length != 1) {
|
| print('''
|
| Please provide the name of a service as argument.
|
|
|
| For example:
|
| - dart mdns-sd.dart _workstation._tcp.local''');
|
| + dart mdns-sd.dart [--timeout <timeout>] _workstation._tcp.local''');
|
| return;
|
| }
|
| +
|
| + var name = arguments.rest[0];
|
| +
|
| MDnsClient client = new MDnsClient();
|
| await client.start();
|
| - await for (ResourceRecord ptr in client.lookup(RRType.PTR, args[0])) {
|
| + await for (ResourceRecord ptr in client.lookup(RRType.PTR, name)) {
|
| String domain = ptr.domainName;
|
| await for (ResourceRecord srv in client.lookup(RRType.SRV, domain)) {
|
| String target = srv.target;
|
| await for (ResourceRecord ip in client.lookup(RRType.A, target)) {
|
| - print('Service instance found at $target ($ip).');
|
| + print('Service instance found at $target (${ip.address}).');
|
| }
|
| }
|
| }
|
|
|