mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
Experiment with mdns to resolve a service
This commit is contained in:
37
lib/main_dns.dart
Normal file
37
lib/main_dns.dart
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import 'package:multicast_dns/multicast_dns.dart';
|
||||||
|
|
||||||
|
Future<void> main() async {
|
||||||
|
// Parse the command line arguments.
|
||||||
|
|
||||||
|
var name = '_dartobservatory._tcp.local';
|
||||||
|
name = '_gitjournal._tcp';
|
||||||
|
final MDnsClient client = MDnsClient();
|
||||||
|
// Start the client with default options.
|
||||||
|
await client.start();
|
||||||
|
|
||||||
|
print("Client started");
|
||||||
|
|
||||||
|
//var query = ResourceRecordQuery.serverPointer(name);
|
||||||
|
var query = ResourceRecordQuery.serverPointer(name);
|
||||||
|
|
||||||
|
// Get the PTR recod for the service.
|
||||||
|
await for (var ptr in client.lookup<PtrResourceRecord>(query)) {
|
||||||
|
print("Got ptr $ptr");
|
||||||
|
// 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.');
|
||||||
|
}
|
@ -574,6 +574,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.9.6+3"
|
version: "0.9.6+3"
|
||||||
|
multicast_dns:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: multicast_dns
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.2"
|
||||||
mutex:
|
mutex:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -56,6 +56,7 @@ dependencies:
|
|||||||
in_app_purchase: ^0.3.4+5
|
in_app_purchase: ^0.3.4+5
|
||||||
flutter_plugin_android_lifecycle: ^1.0.8 # for fixing the build
|
flutter_plugin_android_lifecycle: ^1.0.8 # for fixing the build
|
||||||
timeago: ^2.0.27
|
timeago: ^2.0.27
|
||||||
|
multicast_dns: ^0.2.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: "^0.7.2"
|
flutter_launcher_icons: "^0.7.2"
|
||||||
|
Reference in New Issue
Block a user