Skip to main content

BeaconSender

Struct BeaconSender 

Source
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

Source

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

Source

pub fn send_loop(&self, period: Duration) -> Result<()>

Enter an infinite loop sending Beacons periodically

Source

pub fn send_one_beacon(&self) -> Result<usize>

Send a single Beacon out

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.