본문으로 건너뛰기

Session 세션 — OpcUaSession

OpcUaSession 이는 Client의 Java SDK 기본 클래스(C#의 에 해당 DarraOpcUa)이며, 하나의 인스턴스가 하나의 에 해당합니다 OPC UA Session. 모든 액세스(읽기/쓰기/ /구독/ Browse Call /이력)는 이 객체를 통해 이루어집니다.

구현 AutoCloseable, 반드시에서 try-with-resources 사용해야 하며, 그렇지 않으면 네이티브 리소스와 서버 측 세션이 유출될 수 있습니다.

하위 페이지 이동
  • 구조 및 연결 매개변수는 다음을 참조하십시오. 생성자.
  • 연결/해제 방법은 다음을 참조하십시오. 연결 관리.
  • 단일 항목 / 일괄 읽기/쓰기에 대해서는 다음을 참조하십시오. Read / Write.
  • 내부 사건 통합 채널에 대해서는 다음을 참조하십시오. Events.
  • 네임스페이스 역조회에 대해서는 다음을 참조하십시오. Namespaces.
  • 하트비트 및 세션 유지에 대해서는 다음을 참조하십시오. KeepAlive.

공용 필드 / 속성​

분류속성유형접근설명
연결getEndpointUrl()StringR생성 시 지정된 엔드포인트 URL
getSecurityMode()Enums.MessageSecurityModeR보안 모드 (None / Sign / SignAndEncrypt)
상태getState()Enums.SessionStateR현재 세션 상태 (Disconnected / Connecting / Connected / Reconnecting / Closing / Failed)
isConnected()booleanR연결되어 있는지 여부 (= getState() == Connected)
자식 객체nodesNodeCollectionRLazy Load 노드 액세서(final 필드)
namespacesNamespaceCollectionR네임스페이스 URI ↔ 인덱스 상호 변환 (final 필드)
이벤트eventsOpcUaEventsR세션 수준 이벤트 통합 채널 (Connected / Disconnected / DataChange / ServerEvent / ...) (final 필드)
구성getKeepAliveIntervalMs() / setKeepAliveIntervalMs(int)intRWKeepAlive 하트비트 주기 (기본값 10000 ms, 0 = 비활성화)
isAutoPublish() / setAutoPublish(boolean)booleanRW백그라운드 Publish 스레드 활성화/비활성화 (연결 후 기본값은 true)
내부handle()intRC 계층 핸들 (디버깅용)

공용 메서드​

연결 관리​

  • connect() — 연결 설정 (Hello → SecureChannel → Session → Activate)
  • disconnect() — 수동으로 연결 끊기, 인스턴스 재연결 가능
  • close() — 리소스 해제, 자동 연결 해제 (AutoCloseable에서 가져옴)

하트비트와 발행​

  • publish(int timeoutMs) — Publish를 한 번 수동으로 실행합니다(일반적으로 호출할 필요가 없음).

읽기 / 쓰기​

열람​

구독하기​

메서드 호출​

이력​

제어​

  • cancel(int requestHandle) — 완료되지 않은 요청 취소

전체 예시​

import com.darra.opcua.*;
import com.darra.opcua.OpcUaEvents.ConnectionEventArgs;

try (OpcUaSession ua = new OpcUaSession("opc.tcp://localhost:4840")) {
ua.events.onConnected.add(e ->
System.out.println("Connected to " + e.endpointUrl));
ua.events.onDisconnected.add(e ->
System.out.println("Disconnected: " + e.message));
ua.connect();

// 읽기
try (OpcUaDataValue dv = ua.read("ns=2;s=Temperature")) {
System.out.println("T = " + dv.variant().asDouble() + " °C");
}

// 쓰기
try (OpcUaVariant v = new OpcUaVariant().setDouble(42.0)) {
Enums.StatusCode st = ua.write("ns=2;s=Setpoint", v);
System.out.println("Write status = " + st);
}

// 구독하기
try (OpcUaSubscription sub = ua.createSubscription(500.0)) {
sub.add("ns=2;s=Counter", e ->
System.out.println(e.nodeId + " = " + e.valueString + " (" + e.status + ")"));
Thread.sleep(60_000);
}
}

다음 단계​