Crates.io | async-zeroconf |
lib.rs | async-zeroconf |
version | 0.2.2 |
source | src |
created_at | 2021-08-27 13:44:50.557583 |
updated_at | 2021-09-15 20:42:31.289671 |
description | Async library for wrapping Zeroconf implemenations for use with Tokio |
homepage | https://github.com/martiansoup/async-zeroconf-rs |
repository | https://github.com/martiansoup/async-zeroconf-rs |
max_upload_size | |
id | 443091 |
size | 90,290 |
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.
#[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(())
}
#[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(())
}
#[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(())
}
host
/txt
on Service
publish
is now an async function as it waits for errorsasync-zeroconf
can be licensed under the MIT license or the Apache 2.0 license.