본문으로 건너뛰기

서버 정보

개요​

OPC UA 표준 노드 i=2256 (Server.ServerStatus)는 서버 런타임 정보를 노출합니다.SDK 11개의 리프 노드(i=2257 / i=2258 / i=2259 / i=2261..i=2266 / i=2992 / i=2993, 객체 i=2260 BuildInfo 노드 자체는 건너뜁니다)를 필드별로 읽어서 한 번에 강타입으로 조립합니다 ServerStatus.

해당 규격 조항: 제5부 §6.3.

개별 필드 읽기 실패 시 기본값을 사용(Instant = null / String = null / secondsTillShutdown = 0), 전체적인 예외 발생 시 state 설정 ServerState.Unknown; readServerState() / readCurrentTime() 실패 시 각각 ServerState.Unknown / 를 반환하며 null, 예외는 발생하지 않습니다.

API​

방법분류읽기 및 쓰기설명
ua.readServerStatus()진단읽기완전한 ServerStatus를 반환합니다
ua.readServerState()진단읽기ServerState 열거형을 반환합니다
ua.readCurrentTime()진단읽기Instant(UTC)를 반환합니다

관련 구조:

// ServerStatus / BuildInfo 모두 record — 공개 필드가 없으므로, 일률적으로 액세서리(괄호 포함)를 사용
public final record ServerStatus(Instant startTime, Instant currentTime, ServerState state,
BuildInfo build, long secondsTillShutdown, String shutdownReason) { }

public final record BuildInfo(String productUri, String manufacturerName, String productName,
String softwareVersion, String buildNumber, Instant buildDate) { }

// 'build' 필드 이름은 build(가 아니라 buildInfo)이며, 데이터 유형은 long(int가 아님)입니다 secondsTillShutdown .
public enum ServerState {
Running, // 정상
Failed, // 치명적인 오류
NoConfiguration, // 설정이 누락되었습니다
Suspended, // 운영팀에 의해 일시 중지됨
Shutdown, // 중단 중
Test, // 테스트 모드
CommunicationFault, // 링크 장애
Unknown // SDK 최종 책임
}

ServerState 최상위 열거형( Enums 안에 포함되지 않음)이며, 상수 이름은 PascalCase로 표기됩니다.

코드 예시​

import com.darra.opcua.*;
import java.time.Duration;
import java.time.Instant;

try (OpcUaSession ua = new OpcUaSession("opc.tcp://localhost:4840")) {
ua.connect();

// 1) 일회용
ServerStatus status = ua.readServerStatus();
System.out.println("Start = " + status.startTime());
System.out.println("Now = " + status.currentTime());
System.out.println("State = " + status.state());
System.out.println("Build = " + status.build());

if (status.state() != ServerState.Running)
System.out.println("⚠ 服务端非 Running, 倒计时 " + status.secondsTillShutdown() + "s");

// 2) 경량 하트비트
if (ua.readServerState() == ServerState.Running)
statusLabel.setText("在线");

// 3) 클럭 드리프트
Instant serverNow = ua.readCurrentTime();
if (serverNow != null) {
long driftMs = Duration.between(serverNow, Instant.now()).toMillis();
System.out.printf("时钟差 = %d ms%n", driftMs);
}
}

다국어 대조​

C#PythonJavaC++RustC
ReadServerStatusread_server_statusreadServerStatusReadServerStatusread_server_statusDarraUa_Session_ReadServerStatus
ReadServerStateread_server_statereadServerStateReadServerStateread_server_stateDarraUa_Session_ReadServerState

다음 단계​