-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add mDNS client #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 38 commits
cda0d64
5242a77
8394100
3147614
1aecdd0
b753a49
bd21b36
5eae734
be10902
67e73fc
51c2879
8ba84d1
2b2fe61
afd0ffa
27e32bb
a02b198
372e481
13440cc
a062a28
0a158b2
cf98f1f
2d8f0ab
f962358
a223011
1ae7747
8a711b9
60f3635
a935aee
4aba212
cefc13b
dcf69e4
2c09d26
d0071bd
af7a0df
14826cb
f3a79a8
b9572ba
9dbb4dd
5bcabe2
1961d9f
0eb9bc1
d379223
8d3c4e2
64902f4
b8251d9
2ad7aea
09b47d2
0962e7d
3d2f2a4
4a0974d
de88b93
3602baa
bceebbd
b5b1d4e
554ac6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| .idea | ||
| .packages | ||
| .pub/ | ||
| .dart_tool/ | ||
|
|
||
| pubspec.lock | ||
|
|
||
| Podfile.lock | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ## 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| Copyright 2014 The Chromium Authors. All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are | ||
| met: | ||
|
|
||
| * Redistributions of source code must retain the above copyright | ||
| notice, this list of conditions and the following disclaimer. | ||
| * Redistributions in binary form must reproduce the above | ||
| copyright notice, this list of conditions and the following | ||
| disclaimer in the documentation and/or other materials provided | ||
| with the distribution. | ||
| * Neither the name of Google Inc. nor the names of its | ||
| contributors may be used to endorse or promote products derived | ||
| from this software without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Multicast DNS package | ||
|
|
||
| []( | ||
| https://pub.dartlang.org/packages/multicast_dns) | ||
|
|
||
| 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](https://flutter.io/platform-plugins/). | ||
|
|
||
| ## Example | ||
|
|
||
| Import the library via | ||
| ``` dart | ||
| 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](example/main.dart) or the sample implementations in | ||
| the [bin](bin/) directory. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // 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(ResourceRecordQuery.ptr(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(ResourceRecordQuery.srv(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 obvservatory instance found at ${srv.target}:${srv.port} for "$bundleId".'); | ||
|
||
| } | ||
| } | ||
| client.stop(); | ||
|
|
||
| print('Done.'); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright (c) 2015, the Dartino 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 lookup names | ||
| // on the local network. | ||
|
|
||
| import 'package:multicast_dns/multicast_dns.dart'; | ||
|
|
||
| void main(List<String> args) async { | ||
| if (args.length != 1) { | ||
| print(''' | ||
| Please provide an address as argument. | ||
|
|
||
| For example: | ||
| dart mdns-resolve.dart dartino.local'''); | ||
| return; | ||
| } | ||
|
|
||
| final String name = args[0]; | ||
|
|
||
| final MDnsClient client = MDnsClient(); | ||
| await client.start(); | ||
| await for (IPAddressResourceRecord record | ||
| in client.lookup(ResourceRecordQuery.a(name))) { | ||
| print('Found address (${record.address}).'); | ||
| } | ||
|
|
||
| await for (IPAddressResourceRecord record | ||
| in client.lookup(ResourceRecordQuery.aaaa(name))) { | ||
| print('Found address (${record.address}).'); | ||
| } | ||
| client.stop(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright (c) 2015, the Dartino 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 services | ||
| // on the local network. | ||
|
|
||
| import 'package:multicast_dns/multicast_dns.dart'; | ||
|
|
||
| void main(List<String> args) async { | ||
| if (args.isEmpty) { | ||
| print(''' | ||
| Please provide the name of a service as argument. | ||
|
|
||
| For example: | ||
| dart mdns-sd.dart [--verbose] _workstation._tcp.local'''); | ||
| return; | ||
| } | ||
|
|
||
| final bool verbose = args.contains('--verbose') || args.contains('-v'); | ||
| final String name = args.last; | ||
| final MDnsClient client = MDnsClient(); | ||
| await client.start(); | ||
|
|
||
| await for (PtrResourceRecord ptr | ||
| in client.lookup(ResourceRecordQuery.ptr(name))) { | ||
| if (verbose) { | ||
| print(ptr); | ||
| } | ||
| await for (SrvResourceRecord srv | ||
| in client.lookup(ResourceRecordQuery.srv(ptr.domainName))) { | ||
| if (verbose) { | ||
| print(srv); | ||
| } | ||
| if (verbose) { | ||
| await client | ||
| .lookup(ResourceRecordQuery.txt(ptr.domainName)) | ||
| .forEach(print); | ||
| } | ||
| await for (IPAddressResourceRecord ip | ||
| in client.lookup(ResourceRecordQuery.a(srv.target))) { | ||
| if (verbose) { | ||
| print(ip); | ||
| } | ||
| print( | ||
| 'Service instance found at ${srv.target}:${srv.port} with ${ip.address}.'); | ||
| } | ||
| await for (IPAddressResourceRecord ip | ||
| in client.lookup(ResourceRecordQuery.aaaa(srv.target))) { | ||
| if (verbose) { | ||
| print(ip); | ||
| } | ||
| print( | ||
| 'Service instance found at ${srv.target}:${srv.port} with ${ip.address}.'); | ||
| } | ||
| } | ||
| } | ||
| client.stop(); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.