본문으로 건너뛰기

디스커버리

Discovery 상태가 없는 구조(impl 연관 함수)로, 세션 없이도 호출할 수 있습니다. "연결 전에 먼저 탐색"하는 데 사용됩니다:

하위 페이지 이동
  • 특정 서버의 모든 엔드포인트를 나열하려면 다음을 참조하십시오. GetEndpoints.
  • 도메인 내의 LDS 모든 서버를 나열하는 방법은 다음을 참조하십시오. FindServers.

사용 방식​

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

// 1. 먼저 서버에서 어떤 조합을 지원하는지 GetEndpoints 확인합니다.
let endpoints = Discovery::get_endpoints("opc.tcp://server:4840", 10_000)?;

// 2. 일치하는 항목을 하나 선택하세요 (예: 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. 선별한 엔드포인트를 사용하여 실제로 연결하기
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()?;

내부 행동​

Discovery::get_endpoints / find_servers 내부:

  • 프로세스 수준의 싱글 인스턴스 ( initialize() idempotent)
  • 세션이 필요하지 않으며, 엔드포인트에 URL 직접 OPN(None) → 서비스 요청 → CLO
  • RAII guard를 사용하여 잘못된 경로에서도 native result가 해제되도록 보장

Shutdown Stack을 발생시키지 않아, 세션을 이후에도 계속 사용할 수 있게 합니다.

다음 단계​