#async #tokio #zeroconf #dnssd #bonjour

async-zeroconf

Async library for wrapping Zeroconf implemenations for use with Tokio

4 releases

0.2.2 Sep 15, 2021
0.2.1 Sep 7, 2021
0.2.0 Sep 6, 2021
0.1.0 Aug 27, 2021

#1137 in Network programming

Download history 1/week @ 2022-02-03 1/week @ 2022-02-10 9/week @ 2022-02-17 1/week @ 2022-02-24 1/week @ 2022-03-03 13/week @ 2022-03-10 16/week @ 2022-03-17 3/week @ 2022-03-24 1/week @ 2022-03-31 5/week @ 2022-04-07 10/week @ 2022-04-14 5/week @ 2022-04-21 13/week @ 2022-04-28 29/week @ 2022-05-05 64/week @ 2022-05-12

111 downloads per month

MIT/Apache

78KB
1.5K SLoC

async-zeroconf

async-zeroconf is a crate to register ZeroConf services and provides a way of keeping the service alive using Tokio rather than a synchronous event loop.

Examples

Publishing a service

#[tokio::main]
async fn main() -> Result<(), async_zeroconf::ZeroconfError> {
    // Create a service description
    let service = async_zeroconf::Service::new("Server", "_http._tcp", 80);
    // Publish the service
    let service_ref = service.publish().await?;
    // Service kept alive until service_ref dropped
    Ok(())
}

Browsing for services

#[tokio::main]
async fn main() -> Result<(), async_zeroconf::ZeroconfError> {
    let mut browser = async_zeroconf::ServiceBrowserBuilder::new("_http._tcp");
    let mut services = browser
        .timeout(tokio::time::Duration::from_secs(2))
        .browse()?;

    while let Some(Ok(v)) = services.recv().await {
        println!("Service = {}", v);
    }
    Ok(())
}

Resolving a service

#[tokio::main]
async fn main() -> Result<(), async_zeroconf::ZeroconfError> {
    let mut browser = async_zeroconf::ServiceBrowserBuilder::new("_http._tcp");
    let mut services = browser
        .timeout(tokio::time::Duration::from_secs(2))
        .browse()?;

    while let Some(Ok(v)) = services.recv().await {
        let resolved_service = async_zeroconf::ServiceResolver::r(&v).await?;
        println!("Service = {}", resolved_service);
    }
    Ok(())
}

Changelog

  • 0.2.2
    • Add accessors for host/txt on Service
  • 0.2.1
    • Fix minor issue with C types
  • 0.2.0
    • Fix issues with errors on publishing a service
    • publish is now an async function as it waits for errors
  • 0.1.0
    • Initial version

License

async-zeroconf can be licensed under the MIT license or the Apache 2.0 license.

Dependencies

~3–11MB
~182K SLoC