pub struct BeaconListener { /* private fields */ }Expand description
BeaconListener listens for new Beacons on the specified port
§Example of using BeaconListener with timeout
use simpdiscoverylib::BeaconListener;
use std::time::Duration;
use portpicker::pick_unused_port;
let listening_port = pick_unused_port().expect("Could not get a free port to listen on");
let listener = BeaconListener::new("_my_service._tcp.local".as_bytes(), listening_port)
.expect("Could not create listener");
// Avoid blocking tests by setting a short timeout, expect an error, as there is no sender setup
assert!(listener.wait(Some(Duration::from_millis(1))).is_err());Implementations§
Source§impl BeaconListener
impl BeaconListener
Sourcepub fn new(service_name: &[u8], listening_port: u16) -> Result<Self>
pub fn new(service_name: &[u8], listening_port: u16) -> Result<Self>
Create a new BeaconListener on port with an option filter to be applied to incoming
beacons. This binds to address “0.0.0.0:listening_port”
Sourcepub fn wait(&self, timeout: Option<Duration>) -> Result<Beacon>
pub fn wait(&self, timeout: Option<Duration>) -> Result<Beacon>
Wait for a Beacon on the port specified in BeaconListener::new()
If timeout is None, then it will block forever waiting for a beacon matching the optional
filter (if supplied) in BeaconListener::new(). If no filter was supplied it will block
waiting for any beacon to be received.
If timeout is Some(Duration) then it will block for that duration on the reception of
each beacon. If the beacon does not match a supplied filter then it will loop (blocking
for duration each time until a matching beacon is found.
Auto Trait Implementations§
impl Freeze for BeaconListener
impl RefUnwindSafe for BeaconListener
impl Send for BeaconListener
impl Sync for BeaconListener
impl Unpin for BeaconListener
impl UnwindSafe for BeaconListener
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