Server Information
Overview
OPC UA standard node i=2256 (Server.ServerStatus) exposes server-side runtime information. The SDK reads the 11 leaf nodes field by field (i=2257 / i=2258 / i=2259 / i=2261..i=2266 / i=2992 / i=2993, skipping the i=2260 BuildInfo object node itself) and assembles them in one pass into the strongly typed ServerStatus.
Corresponding section of the standard: Part 5 §6.3.
If a single field fails to read, use the default value (Integer = null / String = null / secondsTillShutdown = 0); if a general exception occurs, state set ServerState.Unknown; readServerState() / readCurrentTime() failure returns ServerState.Unknown / respectively null; none of these throw exceptions.
API
| Methods | Category | Reading and Writing | Note |
|---|---|---|---|
| ua.readServerStatus() | Diagnosis | Read | Returns the Full Version ServerStatus |
| ua.readServerState() | Diagnosis | Read | Returns the ServerState Enumeration |
| ua.readCurrentTime() | Diagnosis | Read | Returns Instant (UTC) |
Related Structures:
// ServerStatus / BuildInfo All are records — no public fields; always use accessors (in parentheses)
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) { }
// Note that the field name is "build" (not buildInfo), and the data type secondsTillShutdown is long (not int).
public enum ServerState {
Running, // Normal
Failed, // Fatal Failure
NoConfiguration, // Missing configuration
Suspended, // Paused by Operations
Shutdown, // Shutting Down
Test, // Test Mode
CommunicationFault, // Link Failure
Unknown // SDK Safety Net
}
ServerState It is a top-level enumeration (not Enums inside ), and the constant names are in PascalCase.
Code Example
import com.darra.opcua.*;
import java.time.Duration;
import java.time.Instant;
try (OpcUaSession ua = new OpcUaSession("opc.tcp://localhost:4840")) {
ua.connect();
// 1) Disposable
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) Lightweight Heartbeat
if (ua.readServerState() == ServerState.Running)
statusLabel.setText("在线");
// 3) Clock drift
Instant serverNow = ua.readCurrentTime();
if (serverNow != null) {
long driftMs = Duration.between(serverNow, Instant.now()).toMillis();
System.out.printf("时钟差 = %d ms%n", driftMs);
}
}
Cross-Language Comparison
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| ReadServerStatus | read_server_status | readServerStatus | ReadServerStatus | read_server_status | DarraUa_Session_ReadServerStatus |
| ReadServerState | read_server_state | readServerState | ReadServerState | read_server_state | DarraUa_Session_ReadServerState |