pub struct MdnsConfig {
pub query_interval: Duration,
pub query_timeout: Option<Duration>,
pub local_names: Vec<String>,
pub local_ip: Option<IpAddr>,
}Expand description
MdnsConfiguration for an mDNS connection.
Use the builder pattern to construct a configuration:
use rtc_mdns::MdnsConfig;
use std::time::Duration;
let config = MdnsConfig::new()
.with_query_interval(Duration::from_millis(500))
.with_local_names(vec!["myhost.local".to_string()]);§Fields
query_interval: How often to retry unanswered queries (default: 1 second)query_timeout: Maximum time to wait for a query answer (default: None - no timeout)local_names: Names this connection will respond to (empty by default)local_addr: IP address to advertise in responses (required for server mode)
Fields§
§query_interval: DurationHow often to retry unanswered queries.
When a query is started, it will be retried at this interval until either an answer is received or the query is cancelled.
Default: 1 second
§Example
use rtc_mdns::MdnsConfig;
use std::time::Duration;
// Retry queries every 500ms for faster discovery
let config = MdnsConfig::default()
.with_query_interval(Duration::from_millis(500));query_timeout: Option<Duration>Maximum time to wait for a query to be answered.
When set, queries that haven’t received an answer within this duration
will emit MdnsEvent::QueryTimeout and
be automatically cancelled.
When None, queries will retry indefinitely until answered or
manually cancelled.
Default: None (no automatic timeout)
§Example
use rtc_mdns::MdnsConfig;
use std::time::Duration;
// Timeout queries after 5 seconds
let config = MdnsConfig::default()
.with_query_timeout(Duration::from_secs(5));local_names: Vec<String>Local names that this connection will respond to.
When an mDNS query arrives for any of these names, the connection
will automatically generate a response with the configured local_addr.
Names should be in .local format (e.g., "myhost.local").
Trailing dots are optional and will be normalized internally.
Default: empty (no names to respond to)
§Example
use rtc_mdns::MdnsConfig;
let config = MdnsConfig::default()
.with_local_names(vec![
"mydevice.local".to_string(),
"printer.local".to_string(),
]);local_ip: Option<IpAddr>Local address to advertise in mDNS responses.
This IP address will be included in A record responses when
queries for local_names are received.
Required if local_names is non-empty, otherwise responses
cannot be generated.
Default: None
§Example
use rtc_mdns::MdnsConfig;
use std::net::{IpAddr, Ipv4Addr};
let config = MdnsConfig::default()
.with_local_names(vec!["myhost.local".to_string()])
.with_local_ip(
IpAddr::V4(Ipv4Addr::new(192, 168, 1, 42)),
);Implementations§
Source§impl MdnsConfig
impl MdnsConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new configuration with default values.
Equivalent to MdnsConfig::default().
§Example
use rtc_mdns::MdnsConfig;
let config = MdnsConfig::new();Sourcepub fn with_query_interval(self, interval: Duration) -> Self
pub fn with_query_interval(self, interval: Duration) -> Self
Set the query retry interval.
Queries will be retried at this interval until answered or cancelled. A value of zero will use the default interval (1 second).
§Arguments
interval- Duration between query retries
§Example
use rtc_mdns::MdnsConfig;
use std::time::Duration;
let config = MdnsConfig::default()
.with_query_interval(Duration::from_millis(250));Sourcepub fn with_query_timeout(self, timeout: Duration) -> Self
pub fn with_query_timeout(self, timeout: Duration) -> Self
Set the query timeout.
When set, queries that don’t receive an answer within this duration
will emit MdnsEvent::QueryTimeout
and be automatically removed from the pending list.
§Arguments
timeout- Maximum duration to wait for a query answer
§Example
use rtc_mdns::MdnsConfig;
use std::time::Duration;
// Queries will timeout after 5 seconds
let config = MdnsConfig::default()
.with_query_timeout(Duration::from_secs(5));
// Combined with retry interval: retry every 500ms, give up after 3s
let config = MdnsConfig::default()
.with_query_interval(Duration::from_millis(500))
.with_query_timeout(Duration::from_secs(3));Sourcepub fn with_local_names(self, names: Vec<String>) -> Self
pub fn with_local_names(self, names: Vec<String>) -> Self
Set the local names to respond to.
When mDNS queries for these names are received, the connection
will automatically generate responses with the configured local_addr.
§Arguments
names- List of hostnames (e.g.,["myhost.local"])
§Example
use rtc_mdns::MdnsConfig;
let config = MdnsConfig::default()
.with_local_names(vec!["server.local".to_string()]);Sourcepub fn with_local_ip(self, local_ip: IpAddr) -> Self
pub fn with_local_ip(self, local_ip: IpAddr) -> Self
Set the local address to advertise in responses.
This address will be included in A record responses. The port is typically 5353 for mDNS.
§Arguments
addr- Socket address containing the IP to advertise
§Example
use rtc_mdns::MdnsConfig;
use std::net::{IpAddr, Ipv4Addr};
let config = MdnsConfig::default()
.with_local_ip(
IpAddr::V4(Ipv4Addr::new(10, 0, 0, 5)),
);Trait Implementations§
Source§impl Clone for MdnsConfig
impl Clone for MdnsConfig
Source§fn clone(&self) -> MdnsConfig
fn clone(&self) -> MdnsConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more