mdns_responder 0.0.2 copy "mdns_responder: ^0.0.2" to clipboard
mdns_responder: ^0.0.2 copied to clipboard

A Flutter plugin for publishing mDNS (Multicast DNS) services on Android and iOS

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:mdns_responder/mdns_responder.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  MdnsResponder mdnsResponderPlugin = MdnsResponder();

  @override
  void initState() {
    super.initState();
    _startMdnsResponder();
  }

  Future<void> _startMdnsResponder() async {
    final service = MdnsService(
      name: 'peer-abc123',
      type: '_p2p._udp',
      port: 4001,
      hostAddresses: ['192.168.1.42', '10.0.0.120', '2001:db8:85a3::8a2e:370:7334'],
      attributes: {'id': 'QmPeerID', 'proto': 'libp2p'},
      subtypes: ['_libp2p'],
    );

    mdnsResponderPlugin
        .publishService(service)
        .then((_) {
          if (kDebugMode) {
            print('Service published: ${service.name}');
          }
        })
        .catchError((error) {
          if (kDebugMode) {
            print('Failed to publish service: $error');
          }
        });

    await Future.delayed(const Duration(seconds: 5));

    mdnsResponderPlugin
        .stopService()
        .then((_) {
          if (kDebugMode) {
            print('Service stopped');
          }
        })
        .catchError((error) {
          if (kDebugMode) {
            print('Failed to stop service: $error');
          }
        });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('mDNS Server Responder example App')),
        body: Center(child: Text('Check Wireshark / other PCAP tool for mDNS packets')),
      ),
    );
  }
}
0
likes
160
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for publishing mDNS (Multicast DNS) services on Android and iOS

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on mdns_responder

Packages that implement mdns_responder