FindServers
- Once you have the server, use GetEndpoints List the available endpoints for this server.
- Then use Constructor True Connection.
Signature
Static method, defined in DarraOpcUa_Client.OpcUaDiscovery:
public static IReadOnlyList<ApplicationDescription> FindServers(
string endpointUrl,
uint timeoutMs = 10_000);
| Parameters | Type | Default | Note |
|---|---|---|---|
| endpointUrl | string | — | Discovery Server endpoint, in the form of opc.tcp://lds-host:4840 |
| timeoutMs | uint | 10_000 | Timeout (milliseconds), default 10 seconds |
Query the Local Discovery Server (LDS) for all registered OPC UA Server. within the same domain. No session is required; the exchange occurs only once: TCP → Hello/Ack → OPN(None) → FindServers → CLO.
endpointUrl Thrown when the value is null or an empty string ArgumentNullException; thrown when delivery fails OpcUaException—
ex.StatusCode this is returned by the server StatusCode.
ApplicationDescription Field
| Field | Type | Note |
|---|---|---|
| ApplicationUri | string | Application URI (Globally Unique Identifier) |
| ProductUri | string | Products URI |
| ApplicationName | string | App Display Name |
| ApplicationType | int | Server (0) / Client (1) / ClientAndServer (2) / DiscoveryServer (3) |
| GatewayServerUri | string | Gateway (optional) |
| DiscoveryProfileUri | string | Discovery Profile |
| DiscoveryUrls | IReadOnlyList<string> | Endpoint URLs for this server |
Usage
using System;
using DarraOpcUa_Client;
var servers = OpcUaDiscovery.FindServers("opc.tcp://lds-host:4840");
Console.WriteLine($"Domain has {servers.Count} servers:");
foreach (var s in servers)
{
Console.WriteLine($"\n App: {s.ApplicationName}");
Console.WriteLine($" AppUri: {s.ApplicationUri}");
Console.WriteLine($" Type: {s.ApplicationType}");
Console.WriteLine($" Discovery URLs:");
foreach (var url in s.DiscoveryUrls)
Console.WriteLine($" - {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 (Specified in the specification, but SDK not provided)
OPC UA Part 4 also defines the FindServersOnNetwork service (mDNS for cross-subnet discovery). The SDK does not expose this service today,
OpcUaDiscovery There are only GetEndpoints / FindServers two methods. If you need cross-subnet discovery, implement it yourself at the business layer.
mDNS / multicast—don't expect SDK to get it by calling.
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:
using System;
using System.Linq;
using DarraOpcUa_Client;
var servers = OpcUaDiscovery.FindServers("opc.tcp://lds:4840");
var primary = servers.FirstOrDefault(s => s.ApplicationUri == "urn:plant:server-primary");
var backup = servers.FirstOrDefault(s => s.ApplicationUri == "urn:plant:server-backup");
var url = primary?.DiscoveryUrls.FirstOrDefault()
?? backup?.DiscoveryUrls.FirstOrDefault();
if (url == null) throw new InvalidOperationException("LDS 里没有可用 Server");
urn:plant:server-primary It is just an example value; the actual value depends on what the server ApplicationDescription.ApplicationUri
has published — it will not FindServers help you classify primary and secondary servers.