Discovery
darra::opcua::Discovery It is a static class, Can be called without a session. Used for "check before connecting":
Subpage Redirect
- To list all endpoints for a specific server, please refer to GetEndpoints.
- To list all servers in LDS the domain, see FindServers.
Header Files
#include <darra/opcua/discovery.hpp>
using namespace darra::opcua;
Both methods are class Discovery 'sStatic Methods, Prototype:
static std::vector<EndpointDescription> GetEndpoints(std::string const& endpoint_url, uint32_t timeout_ms = 10000);
static std::vector<ApplicationDescription> FindServers(std::string const& endpoint_url, uint32_t timeout_ms = 10000);
endpoint_url If successful, return an empty string Exception(..., Status::DarraInvalidArgument); otherwise, return a failure code Exception along with the original status code.
Usage Patterns
#include <darra/opcua/client.hpp>
#include <darra/opcua/discovery.hpp>
using namespace darra::opcua;
Stack::Init();
// 1. First, GetEndpoints check which combinations are supported by the server
auto endpoints = Discovery::GetEndpoints("opc.tcp://server:4840");
// 2. Choose a matching one (e.g., SignAndEncrypt + Username)
EndpointDescription const* picked = nullptr;
for (auto const& ep : endpoints) {
if (ep.security_mode == MessageSecurityMode::SignAndEncrypt) {
for (auto const& t : ep.user_tokens) {
if (t.token_type == UserTokenType::Username) {
picked = &ep;
break;
}
}
if (picked) break;
}
}
if (!picked) throw std::runtime_error("服务端没有 SignAndEncrypt + Username 的 Endpoint");
// 3. Use the selected endpoint to establish an actual connection
ConnectionConfig cfg;
cfg.endpoint_url = picked->endpoint_url;
cfg.security_mode = picked->security_mode;
cfg.security_policy_uri = picked->security_policy_uri;
cfg.user_token_type = UserTokenType::Username; // If no meeting is scheduled, the default is "Anonymous."
cfg.username = "operator";
cfg.password = "secret";
cfg.client_cert_path = "client.pfx"; // PFX File (containing a private key)
cfg.client_key_path = "123456"; // The password PFX for the one above (the field name is a historical remnant; it is not the path to the private key file)
Session s(cfg);
s.Connect();