Crate simpdiscoverylib
source ·Expand description
simpdiscovery
library crate for simple UDP datagram-based discovery of services on a LAN
§Example combining a BeaconSender and a BeaconListener
use simpdiscoverylib::{BeaconSender, BeaconListener};
use std::time::Duration;
use portpicker::pick_unused_port;
let service_port = pick_unused_port().expect("Could not get a free port");
let broadcast_port = pick_unused_port().expect("Could not get a free port");
let my_service_name = "_my_service._tcp.local".as_bytes();
let beacon = BeaconSender::new(service_port, my_service_name, broadcast_port)
.expect("Could not create sender");
std::thread::spawn(move || {
beacon.send_loop(Duration::from_secs(1)).expect("Could not run send_loop")
});
let listener = BeaconListener::new(my_service_name, broadcast_port)
.expect("Could not create listener");
let beacon = listener.wait(None).expect("Failed to receive beacon");
assert_eq!(beacon.service_name, my_service_name, "Received service name doesn't match");
assert_eq!(beacon.service_port, service_port, "Received service port doesn't match");
Structs§
Beacon
contains information about the beacon that was received by aBeaconListener
BeaconListener
listens for newBeacons
on the specified portBeaconSender
is used to send UDP Datagram beacons to the Broadcast IP address on the LAN