pub struct MulticastDiscoverySocket<D: AdvertisementData> { /* private fields */ }Implementations§
Source§impl<D: AdvertisementData> MulticastDiscoverySocket<D>
impl<D: AdvertisementData> MulticastDiscoverySocket<D>
Sourcepub fn new_discover_only(cfg: &MulticastDiscoveryConfig) -> Result<Self>
pub fn new_discover_only(cfg: &MulticastDiscoveryConfig) -> Result<Self>
Create new socket for multicast discovery. Announcements are disabled (running without service)
Enable feature bincode for passing Encode + Decode types as adv_data
Sourcepub fn new_with_service(
cfg: &MulticastDiscoveryConfig,
service_port: u16,
initial_adv_data: D,
) -> Result<Self>
pub fn new_with_service( cfg: &MulticastDiscoveryConfig, service_port: u16, initial_adv_data: D, ) -> Result<Self>
Create new socket for multicast discovery. Announcements are enabled depending on config.
Enable feature bincode for passing Encode + Decode types as adv_data
Sourcepub fn discover_id(&self) -> u32
pub fn discover_id(&self) -> u32
Returns discover ID. It is generated randomly, and can be used to detect client application restart.
pub fn running_port(&self) -> MulticastRunningPort
Sourcepub fn set_announce_en(&mut self, en: bool)
pub fn set_announce_en(&mut self, en: bool)
Setting this to false will disable periodic background announcements during poll()
Announcements are performed by periodic sending message Announce (and ExtendAnnounce)
Sourcepub fn set_discover_replies_en(&mut self, enable: bool)
pub fn set_discover_replies_en(&mut self, enable: bool)
Setting this to false will disable automatic replies to Discovery messages
Sourcepub fn adv_data(&mut self) -> Option<&mut D>
pub fn adv_data(&mut self) -> Option<&mut D>
Guaranteed to return Some(&mut D) if was created with Self::new
Sourcepub fn discover(&mut self)
pub fn discover(&mut self)
Manually discover all clients on main or backup ports (using Discovery message).
Results can be collected by running poll.
Sourcepub fn poll(&mut self, discover_msg: impl FnMut(PollResult<'_, D>))
pub fn poll(&mut self, discover_msg: impl FnMut(PollResult<'_, D>))
Run poll periodically to handle internal discovery mechanisms:
Announcemessages periodic sendingExtendAnnouncemessages periodic sending (if running on backup port)- handling incoming messages (and returning discovery results via
discover_msgcallback)
It is recommended to call this function in a loop with ~100ms sleep