FindServers
- 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>,
}
| Field | Note |
|---|---|
| application_uri | Application URI (Globally Unique Identifier) |
| product_uri | Products URI |
| application_name | App Display Name |
| application_type | Application Type (see above) |
| discovery_urls | Endpoint 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
| API | Input | Output |
|---|---|---|
| find_servers | LDS URL | Server List (Across Multiple Hosts) |
| get_endpoints | Single Server URL | List 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
| StatusCode | Reason |
|---|---|
| BAD_COMMUNICATION_ERROR | LDS Unreachable |
| BAD_TIMEOUT | timeout_ms timeout |
| INVALID_ARGUMENT | endpoint_url is empty / contains NUL |
| Empty list | LDS No servers are registered. |