mdns_responder 0.0.2
mdns_responder: ^0.0.2 copied to clipboard
A Flutter plugin for publishing mDNS (Multicast DNS) services on Android and iOS
๐ฐ๏ธ mdns_responder #
A Flutter plugin for publishing mDNS (Multicast DNS) services on Android and iOS, with support for advanced features like TXT records, host addresses, subtypes, and libp2p compatibility.
โ Supports NetService (Bonjour) on iOS
โ Uses NsdManager on Android
โ Compatible with libp2p, IPFS, and other P2P service discovery protocols
โจ Features #
- Publish mDNS services with:
- Service name, type, and port
- Host IP addresses (Android only)
- TXT record attributes (key-value pairs)
- Subtypes (Android 14+ only)
- Network identifier (Android only)
- Fully asynchronous Dart API
- Platform channel implementation
- Tested with
dns-sdandavahi-browse
๐ Getting Started #
1. Add to pubspec.yaml #
dependencies:
mdns_responder:
git:
url: https://github.com/eelco2k/mdns_responder.git
2. Platform Setup #
โ Android
Add the following to your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Subtypes require Android 14+ (API 34).
โ iOS
Add Bonjour service types to Info.plist:
<key>NSBonjourServices</key>
<array>
<string>_p2p._udp</string>
</array>
โ Usage #
Import the plugin #
import 'package:mdns_responder/mdns_responder.dart';
import 'package:mdns_responder/models/mdns_service.dart';
Publish a service #
final service = MdnsService(
name: 'peer-abc123',
type: '_p2p._udp',
port: 4001,
hostAddresses: ['192.168.1.42'], // Android only
attributes: {
'id': 'QmPeerID',
'proto': 'libp2p',
},
subtypes: ['_libp2p'], // Android 14+ only
);
await MdnsResponder().publishService(service);
Stop the service #
await MdnsResponder().stopService();
๐งช Testing #
Unit tests #
flutter test
Includes tests for:
- MdnsService serialization
- Mock platform interface
- Method channel communication
Integration test (example app) #
flutter drive \
--driver integration_test/driver.dart \
--target integration_test/mdns_test.dart
You can also test manually using dns-sd or avahi-browse on the same network.
๐ Service Discovery #
To verify your service is visible:
On macOS #
dns-sd -B _p2p._udp
On Linux #
avahi-browse -a
You should see your peer-abc123 service appear.
๐ฆ API Reference #
MdnsService Fields #
| Field | Type | Description |
|---|---|---|
| name | String | Instance name of the service |
| type | String | Service type (e.g. _http._tcp) |
| port | int | Port number |
| hostAddresses | List | IP addresses (Android only) |
| attributes | Map<String, String>? | TXT record key-value pairs |
| subtypes | List | Subtypes (Android 14+ only) |
| network | String? | Network ID (Android only) |
๐ ๏ธ Roadmap #
- โ Windows / Linux support via FFI or CLI
- โ libp2p TXT record helpers
- โ Subtypes for iOS
๐ฅ Contributing #
Pull requests are welcome! Please include tests and follow the existing code style.
๐ License #
MIT License ยฉ 2025 Syzygy interactive media