| Crates.io | switchy_mdns |
| lib.rs | switchy_mdns |
| version | 0.1.4 |
| created_at | 2025-05-07 21:30:45.394528+00 |
| updated_at | 2025-07-21 19:28:13.561816+00 |
| description | Switchy mdns service discovery package |
| homepage | |
| repository | https://github.com/MoosicBox/MoosicBox |
| max_upload_size | |
| id | 1664557 |
| size | 31,604 |
Simple multicast DNS (mDNS) service registration library for the MoosicBox ecosystem, providing basic service announcement capabilities on local networks using the Zeroconf/Bonjour protocol.
Add this to your Cargo.toml:
[dependencies]
moosicbox_mdns = "0.1.1"
# Enable scanner feature for network discovery
moosicbox_mdns = { version = "0.1.1", features = ["scanner"] }
use moosicbox_mdns::{register_service, RegisterServiceError};
#[tokio::main]
async fn main() -> Result<(), RegisterServiceError> {
// Register a MoosicBox service on the network
register_service(
"MyMusicServer", // instance name
"192.168.1.100", // IP address
8000, // port
).await?;
println!("MoosicBox service registered successfully!");
// Keep the service running
tokio::signal::ctrl_c().await.unwrap();
Ok(())
}
The library uses a standard service type for MoosicBox servers:
use moosicbox_mdns::SERVICE_TYPE;
println!("Service type: {}", SERVICE_TYPE); // "_moosicboxserver._tcp.local."
use moosicbox_mdns::RegisterServiceError;
match register_service("MyServer", "192.168.1.100", 8000).await {
Ok(()) => println!("Service registered successfully"),
Err(RegisterServiceError::MdnsSd(e)) => {
eprintln!("mDNS error: {}", e);
}
Err(RegisterServiceError::IO(e)) => {
eprintln!("I/O error: {}", e);
}
}
mdns-sd: Core mDNS service daemon functionalityhostname: System hostname detectionthiserror: Error handling utilitiesRegisterServiceError: Wraps mDNS and I/O errors during service registrationThe library provides a simple interface for announcing MoosicBox services on local networks, making them discoverable by other devices using standard mDNS/Bonjour protocols.