Skip to main content

findServers

Preliminary / Supporting
  • Once you have the server, use GetEndpoints List the available endpoints for this server.
  • Then use Constructor True Connection.

Signature​

public static List<ApplicationDescription> findServers(String discoveryUrl);
public static List<ApplicationDescription> findServers(String discoveryUrl, int timeoutMs);

Query the Local Discovery Server (LDS) for all registered OPC UA Server. within the same domain. The default timeout is 10 seconds.

ApplicationDescription Field​

MethodsTypeNote
getApplicationUri()StringApplication URI (Globally Unique Identifier)
getProductUri()StringProducts URI
getApplicationName()StringApp Display Name
getApplicationType()int0=Server / 1=Client / 2=ClientAndServer / 3=DiscoveryServer
getGatewayServerUri()StringGateway (optional)
getDiscoveryProfileUri()StringDiscovery Profile
getDiscoveryUrls()List<String>Endpoint URLs for this server

Usage​

List<ApplicationDescription> servers =
OpcUaDiscovery.findServers("opc.tcp://lds-host:4840");

System.out.println("Domain has " + servers.size() + " servers:");
for (ApplicationDescription s : servers) {
System.out.println();
System.out.println(" App: " + s.getApplicationName());
System.out.println(" AppUri: " + s.getApplicationUri());
System.out.println(" Type: " + s.getApplicationType());
System.out.println(" Discovery URLs:");
for (String url : s.getDiscoveryUrls()) {
System.out.println(" - " + url);
}
}

LDS​

LDS = Local Discovery Server, provided OPC Foundation by. When a server on the same subnet starts up, it can register with LDS, and clients can findServers discover all of them via.

LDS By default, it listens on port 4840 (the same port as a standard server). It is typically installed on a dedicated host, but can also be deployed alongside the server.

FindServersOnNetwork (Extension)​

LDS There is also a service FindServersOnNetwork that can be discovered across subnets via mDNS. Currently, this is not SDK exposed API; if needed, you can use low-level calls.

Use Case: Automatic Server Failover (Redundancy)​

In a redundant configuration, both the primary and standby servers are registered with the same client LDS. The client periodically checks their status findServersand switches to the standby server if the primary server becomes unreachable:

List<ApplicationDescription> servers = OpcUaDiscovery.findServers("opc.tcp://lds:4840");

ApplicationDescription primary = servers.stream()
.filter(s -> "urn:plant:server-primary".equals(s.getApplicationUri()))
.findFirst().orElse(null);

ApplicationDescription backup = servers.stream()
.filter(s -> "urn:plant:server-backup".equals(s.getApplicationUri()))
.findFirst().orElse(null);

String url = (primary != null && !primary.getDiscoveryUrls().isEmpty())
? primary.getDiscoveryUrls().get(0)
: (backup != null && !backup.getDiscoveryUrls().isEmpty())
? backup.getDiscoveryUrls().get(0)
: null;

Next Step​