Skip to main content

Discovery

Discovery This is a stateless structure (impl association function) that can be called without a session. It is used for "pre-connection detection":

Subpage Redirect
  • To list all endpoints for a specific server, please refer to GetEndpoints.
  • To list all servers in LDS the domain, see FindServers.

Usage Patterns​

use darra_opcua::{Discovery, MessageSecurityMode, UserTokenType, Session, ConnectionConfig};

// 1. First, GetEndpoints check which combinations are supported by the server
let endpoints = Discovery::get_endpoints("opc.tcp://server:4840", 10_000)?;

// 2. Choose a matching one (e.g., SignAndEncrypt + Username)
let ep = endpoints.iter().find(|e| {
e.security_mode == MessageSecurityMode::SignAndEncrypt
&& e.user_tokens.iter().any(|t| t.token_type == UserTokenType::Username)
}).ok_or("no matching endpoint")?;

// 3. Use the selected endpoint to establish an actual connection
let mut cfg = ConnectionConfig::new(&ep.endpoint_url);
cfg.security_mode = ep.security_mode;
cfg.security_policy_uri = Some(ep.security_policy_uri.clone());
cfg.username = Some("operator".into());
cfg.password = Some("secret".into());
cfg.client_cert_path = Some("client.pfx".into());
let mut s = Session::with_config(cfg)?;
s.connect()?;

Internal Behavior​

Discovery::get_endpoints / find_servers Internal:

  • Process-Level Singleton initialize() (idempotent)
  • No session is required; simply send URL OPN(None) directly to the endpoint → service request → CLO
  • Use a guard RAII to ensure that native result is also released if the path is incorrect

It does not shut down the stack, so the session remains available afterward.

Next Step​