Skip to main content

FindServers

Preliminary / Supporting
  • Once you have the server, use GetEndpoints List the available endpoints for this server.
  • Then use Constructor True Connection.

Signature​

pub fn Discovery::find_servers(
endpoint_url: &str,
timeout_ms: u32,
) -> Result<Vec<ApplicationDescription>, OpcUaError>;

Query the Local Discovery Server (LDS) for all OPC UA Server. registered within the same domain.

ApplicationDescription Field​

pub struct ApplicationDescription {
pub application_uri: String,
pub product_uri: String,
pub application_name: String,
pub application_type: i32, // 0=Server / 1=Client / 2=ClientAndServer / 3=DiscoveryServer
pub gateway_server_uri: String,
pub discovery_profile_uri: String,
pub discovery_urls: Vec<String>,
}
FieldNote
application_uriApplication URI (Globally Unique Identifier)
product_uriProducts URI
application_nameApp Display Name
application_typeApplication Type (see above)
discovery_urlsEndpoint URLs for this server

Usage​

use darra_opcua::Discovery;

let servers = Discovery::find_servers("opc.tcp://lds-host:4840", 10_000)?;

println!("Domain has {} servers:", servers.len());
for srv in &servers {
println!("\n App: {}", srv.application_name);
println!(" AppUri: {}", srv.application_uri);
println!(" Type: {}", srv.application_type);
println!(" Discovery URLs:");
for url in &srv.discovery_urls {
println!(" - {}", url);
}
}

LDS​

LDS = Local Discovery Server, OPC Foundation provided by. When a server on the same subnet starts up, it can register with LDS, and clients can FindServers discover all of them via.

LDS By default, it listens on port 4840 (the same port as a standard server). It is typically installed on a dedicated host, but can also be deployed alongside the server.

FindServersOnNetwork (Extension)​

LDS There is also a service FindServersOnNetwork that can be discovered across subnets via mDNS. Currently, this is not SDK exposed API; if needed, you can use low-level calls.

Use Case: Automatic Server Failover (Redundancy)​

In a redundant configuration, both the primary and standby servers are registered with the same client LDS. The client periodically checks their status FindServersand switches to the standby server if the primary server becomes unreachable:

use darra_opcua::{Discovery, Session};

let servers = Discovery::find_servers("opc.tcp://lds:4840", 10_000)?;
let primary = servers.iter().find(|s| s.application_uri == "urn:plant:server-primary");
let backup = servers.iter().find(|s| s.application_uri == "urn:plant:server-backup");

let url = primary
.and_then(|s| s.discovery_urls.first())
.or_else(|| backup.and_then(|s| s.discovery_urls.first()))
.ok_or("no server available")?
.clone();

let mut s = Session::new(&url)?;
s.connect()?;

Difference from GetEndpoints​

APIInputOutput
find_serversLDS URLServer List (Across Multiple Hosts)
get_endpointsSingle Server URLList of Endpoints for This Server (Multiple Combinations on a Single Host)

Typical procedure: find_servers → Obtain Server URL → get_endpoints → Select a specific endpoint → Connect.

Error​

StatusCodeReason
BAD_COMMUNICATION_ERRORLDS Unreachable
BAD_TIMEOUTtimeout_ms timeout
INVALID_ARGUMENTendpoint_url is empty / contains NUL
Empty listLDS No servers are registered.

Next Step​