| Crates.io | multicast-discovery-socket |
| lib.rs | multicast-discovery-socket |
| version | 0.1.3 |
| created_at | 2025-06-29 13:07:24.036604+00 |
| updated_at | 2025-07-17 11:40:54.158369+00 |
| description | Ready to use discovery solution for local networks |
| homepage | |
| repository | https://github.com/skibon02/multicast-discovery-socket |
| max_upload_size | |
| id | 1730748 |
| size | 78,877 |
Integrate local client discovery into your rust application with ease!
What can it do?
bincode::Encode + bincode::Decode<()> + CloneWhat it cannot do?
cfg(windows) - Windows OS. Deps: winapi, if_addrscfg(target_os="linux") - Linux OS. Deps: nix, if_addrscfg(target_os="android") - Android OS (not tested). Deps: nix, if_addrsIf your platform is not listed here, fallback implementation is used (does not support multiple interfaces, only system default interface)
This library works well as a proof of concept, but it is not yet tested enough. You can use it, but you cannot totally rely on it (yet)
Check the discovery example. Run multiple instances of it on the same host/network and see how they discover each other.
let cfg = MulticastDiscoveryConfig::new(Ipv4Addr::new(239, 37, 37, 37), "multicast-example".into())
.with_multicast_port(37337)
.with_backup_ports(62337..62339);
let name = format!("Client {}", rand::random::<u8>());
info!("Running as {name}");
let mut socket = MulticastDiscoverySocket::new(&cfg, Some(12345), name).unwrap();
loop {
socket.poll(|msg| {
match msg {
PollResult::DiscoveredClient {
addr,
discover_id,
adv_data
} => {
println!("Discovered client: {} - {:x}: {:?}", addr, discover_id, adv_data);
}
PollResult::DisconnectedClient {
addr,
discover_id
} => {
println!("Disconnected client: {} - {:x}", addr, discover_id);
}
}
});
thread::sleep(Duration::from_millis(100));
}
Licensed under either of
at your option.
Support for multiple interfaces is hard to be implemented in cross-platform way.
Windows and Linux support is implemented mostly relying on code from multicast-socket
Thanks to Bruno Tavares for his work and research on multicast support!