pub struct BeaconSender { /* private fields */ }Expand description
BeaconSender is used to send UDP Datagram beacons to the Broadcast IP address on the LAN
§Example of using BeaconSender
This example will just exit at the end and the thread above will die along with the process.
In your own code, either:
- don’t start a background thread and just loop forever sending beacons in main thread, or
- have some other way to keep the process (and hence the sending thread) alive so beacons are actually sent before process ends
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 for broadcast");
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 enter send_loop");
});Implementations§
Source§impl BeaconSender
impl BeaconSender
Sourcepub fn new(
service_port: u16,
service_name: &[u8],
broadcast_port: u16,
) -> Result<Self>
pub fn new( service_port: u16, service_name: &[u8], broadcast_port: u16, ) -> Result<Self>
Create a new BeaconSender to send Beacons for a service with name service_name that
should be contacted on the port service_port
Sourcepub fn send_loop(&self, period: Duration) -> Result<()>
pub fn send_loop(&self, period: Duration) -> Result<()>
Enter an infinite loop sending Beacons periodically
Sourcepub fn send_one_beacon(&self) -> Result<usize>
pub fn send_one_beacon(&self) -> Result<usize>
Send a single Beacon out
Auto Trait Implementations§
impl Freeze for BeaconSender
impl RefUnwindSafe for BeaconSender
impl Send for BeaconSender
impl Sync for BeaconSender
impl Unpin for BeaconSender
impl UnsafeUnpin for BeaconSender
impl UnwindSafe for BeaconSender
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more