mdns_plugin 0.0.3 copy "mdns_plugin: ^0.0.3" to clipboard
mdns_plugin: ^0.0.3 copied to clipboard

outdated

mDNS Service discovery

mdns_plugin #

Yet another package which discovers network services on the local network. Presently, this package is in development, and should work for iOS targets. Android targets are forthcoming.

Please file any issues or feature requests on github, thanks.

Example #

Here's a basic example which implements a delegate, that can respond to mDNS services being discovered and updated:

import 'dart:async';
import 'package:mdns_plugin/mdns_plugin.dart';

void main() {
    MDNSPlugin mdns = new MDNSPlugin(Delegate());
    startDiscovery();
    sleep();
    stopDiscovery();
    sleep();
}

void startDiscovery() {      
    _mdns.startDiscovery("_googlecast._tcp").then((_) {
        print("Discovery started");
    });
}

Future sleep() {
  return new Future.delayed(const Duration(seconds: 5), () => "5");
}

class Delegate implements MDNSPluginDelegate {
  void onDiscoveryStarted() {
      print("Discovery started");
  }
  void onDiscoveryStopped() {
      print("Discovery stopped");
  }
  void onServiceFound(MDNSService service) {
      print("Found: $service");
  }
  void onServiceResolved(MDNSService service) {
      print("Resolved: $service");
  }
  void onServiceUpdated(MDNSService service) {
      print("Updated: $service");
  }
  void onServiceRemoved(MDNSService service) {
      print("Removed: $service");
  }
}