Skip to main content

find_servers

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

Signature​

@staticmethod
def find_servers(endpoint_url: str,
timeout_ms: int = 10_000) -> List[ApplicationDescription]: ...

Query the Local Discovery Server (LDS) for all registered devices within the same domain OPC UA Server.

Corresponding section of the standard: OPC UA Part 4 §5.5.3 (FindServers).

Parameters​

ParametersDefaultNote
endpoint_url—The endpoint of the Discovery Server (usually LDS), such as "opc.tcp://lds-host:4840"; an empty string results in an exception ValueError
timeout_ms10_000Timeout (milliseconds); when 0 is passed, treat it as 10 000 ms

Returns an List[ApplicationDescription] empty list if none are registered (no exception is thrown).

ApplicationDescription Field​

FieldTypeNote
application_uriOptional[str]Application URI (Globally Unique Identifier)
product_uriOptional[str]Products URI
application_nameOptional[str]App Display Name
application_typeint0=Server / 1=Client / 2=ClientAndServer / 3=DiscoveryServer
gateway_server_uriOptional[str]Gateway (optional)
discovery_profile_uriOptional[str]Discovery Profile
discovery_urlsList[str]All information published by the app Discovery URL

Usage​

from darra_opcua import OpcUaDiscovery

servers = OpcUaDiscovery.find_servers("opc.tcp://lds-host:4840")

print(f"Domain has {len(servers)} servers:")
for s in servers:
print(f"\n App: {s.application_name}")
print(f" AppUri: {s.application_uri}")
print(f" Type: {s.application_type}")
print(f" Discovery URLs:")
for url in s.discovery_urls:
print(f" - {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 find_servers 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 is discovered across subnets via mDNS. Currently, this service is not SDK exposed API.

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 find_servers and switches to the standby server if the primary server becomes unreachable:

from darra_opcua import OpcUaDiscovery

servers = OpcUaDiscovery.find_servers("opc.tcp://lds:4840")

primary = next((s for s in servers if s.application_uri == "urn:plant:server-primary"), None)
backup = next((s for s in servers if s.application_uri == "urn:plant:server-backup"), None)

pick = primary or backup
url = pick.discovery_urls[0] if pick and pick.discovery_urls else None

Implementation Constraints​

  • Synchronous, blocking call; the timeout is controlled timeout_ms by; The parameter was not removed
  • Returns a maximum of 256 records ApplicationDescription; if the server returns more than that, only the first 256 records are retrieved, and no error is reported
  • The result isRegistered on this Discovery Server (LDS) List of servers; when switching to a different server, LDS the results differ—it turns out that cross-subnet requests must go through FindServersOnNetwork (see above)

Cross-Language Comparison​

C#PythonJavaC++RustC
FindServersfind_serversfindServersDiscovery::FindServersDiscovery::find_serversDarraUa_Discovery_FindServers

Next Step​