3 个不稳定版本
使用旧的 Rust 2015
0.5.0 | 2020 年 2 月 25 日 |
---|---|
0.4.2 | 2019 年 1 月 24 日 |
0.4.1 | 2018 年 11 月 28 日 |
#1680 在 网络编程
30 每月下载次数
65KB
1.5K SLoC
组播 DNS
multicust_dns
- 实质上是 Avahi 的 Rust 封装,内部使用 AvahiDaemon 管理本地网络上的主机名和浏览服务。
成功编译需要 avahi-common
、avahi-client 和
dbus-1
库。
对于没有所需 avahi 库的非 Linux 平台,使用模拟实现。
请参见 Multicast DNS Utils 命令行应用程序作为示例。
示例(请参阅 ./examples
文件夹)
extern crate multicast_dns;
use multicast_dns::host::HostManager;
fn main() {
let host_name = format!("custom-host");
let host_manager = HostManager::new();
if !host_manager.is_valid_name(&host_name).unwrap() {
panic!("Host name `{}` is not a valid host name!", &host_name);
}
// The `new_host_name` can be different from the one we are trying to set,
// due to possible collisions that may happen.
let new_host_name = host_manager.set_name(&host_name).unwrap();
println!("New host name is: {:?}", &new_host_name);
}
或
extern crate multicast_dns;
use multicast_dns::discovery::*;
fn main() {
let service_type = format!("_device-info._tcp");
let discovery_manager = DiscoveryManager::new();
let on_service_resolved = |service: ServiceInfo| {
println!("Service resolved: {:?}", service);
};
let on_service_discovered = |service: ServiceInfo| {
println!("Service discovered: {:?}", service);
let resolve_listeners = ResolveListeners {
on_service_resolved: Some(&on_service_resolved),
};
discovery_manager.resolve_service(service, resolve_listeners);
};
let on_all_discovered = || {
println!("All services has been discovered");
};
let discovery_listeners = DiscoveryListeners {
on_service_discovered: Some(&on_service_discovered),
on_all_discovered: Some(&on_all_discovered),
};
discovery_manager.discover_services(&service_type, discovery_listeners);
}
请参阅 RFC 6762 和 RFC 6763 以获取标准规范。
还可以查看 服务名称和传输协议端口号注册表 以了解当前可用和注册的服务。
依赖关系
~130KB