Skip to main content

GetEndpoints

Preliminary / Supporting
  • After dragging it to the Endpoint, use Constructor Actually establish a session.
  • For cross-service discovery, please use FindServers.

Signature​

namespace darra::opcua {
class Discovery {
public:
static std::vector<EndpointDescription> GetEndpoints(
std::string const& endpoint_url,
uint32_t timeout_ms = 10000);
};
}

Connect to the server in temporary SecureChannel (None mode), retrieve the endpoint list, and then disconnect immediately. No session required, but you must Stack::Init() before calling it.

ParametersDefaultNote
endpoint_url—Endpoint of the target server URL; Passing an empty string throws Exception("endpoint_url 不能为空", Status::DarraInvalidArgument)
timeout_ms10000Total query timeout (milliseconds)

EndpointDescription Field​

struct EndpointDescription {
std::string endpoint_url;
std::string security_policy_uri;
MessageSecurityMode security_mode = MessageSecurityMode::None;
std::string server_application_uri;
std::string server_product_uri;
std::string server_application_name;
int32_t server_application_type = 0; // 0 Server / 1 Client / 2 ClientAndServer / 3 DiscoveryServer
std::vector<uint8_t> server_certificate; // DER, nullable
std::string transport_profile_uri;
uint8_t security_level = 0;
std::vector<UserTokenPolicy> user_tokens;
};
FieldTypeNote
endpoint_urlstd::stringActual endpoint URL
security_policy_uristd::stringAlgorithm Suite URI
security_modeMessageSecurityModeNone (1) / Sign (2) / SignAndEncrypt (3)
server_application_uristd::stringServer-Side Application URI
server_product_uristd::stringServer-Side Products URI
server_application_namestd::stringServer-Side Application Display Name
server_application_typeint32_tServer (0) / Client (1) / ClientAndServer (2) / DiscoveryServer (3)
server_certificatestd::vector<uint8_t>Server certificate (DER), optional
transport_profile_uristd::stringTransmission Profile (usually UA-TCP)
security_leveluint8_tServer-Side Recommendation Priority
user_tokensstd::vector<UserTokenPolicy>Supported Login Methods

UserTokenPolicy Field​

struct UserTokenPolicy {
std::string policy_id;
UserTokenType token_type = UserTokenType::Anonymous;
};
FieldTypeNote
policy_idstd::stringLogin Policy Identifier
token_typeUserTokenTypeAnonymous (0) / Username (1) / Certificate (2) / Issued (3)

Usage​

#include <darra/opcua/discovery.hpp>
#include <iostream>

using namespace darra::opcua;

// The following ModeName / TokenName are local helper functions in the example,
// Not exported SDK ( API SDK no interface provided for enumeration renaming).
static const char* ModeName(MessageSecurityMode m) {
switch (m) {
case MessageSecurityMode::None: return "None";
case MessageSecurityMode::Sign: return "Sign";
case MessageSecurityMode::SignAndEncrypt: return "SignAndEncrypt";
default: return "Invalid";
}
}
static const char* TokenName(UserTokenType t) {
switch (t) {
case UserTokenType::Anonymous: return "Anonymous";
case UserTokenType::Username: return "Username";
case UserTokenType::Certificate: return "Certificate";
case UserTokenType::Issued: return "Issued";
default: return "Unknown";
}
}

Stack::Init();
auto endpoints = Discovery::GetEndpoints("opc.tcp://server:4840");

std::cout << "Server has " << endpoints.size() << " endpoints:\n";
for (auto const& ep : endpoints) {
std::cout << "\n URL: " << ep.endpoint_url
<< "\n Mode: " << static_cast<int>(ep.security_mode)
<< " (" << ModeName(ep.security_mode) << ")"
<< "\n Policy: " << ep.security_policy_uri
<< "\n Tokens:\n";
for (auto const& t : ep.user_tokens) {
std::cout << " - type=" << static_cast<int>(t.token_type)
<< " (" << TokenName(t.token_type) << ")"
<< " policy_id=" << t.policy_id << "\n";
}
}
Stack::Shutdown();

Sample Output​

Server has 3 endpoints:

URL: opc.tcp://server:4840
Mode: 1 (None)
Policy: http://opcfoundation.org/UA/SecurityPolicy#None
Tokens:
- type=0 (Anonymous) policy_id=anonymous

URL: opc.tcp://server:4840
Mode: 2 (Sign)
Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256
Tokens:
- type=0 (Anonymous) policy_id=anonymous
- type=1 (Username) policy_id=username

URL: opc.tcp://server:4840
Mode: 3 (SignAndEncrypt)
Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256
Tokens:
- type=1 (Username) policy_id=username
- type=2 (Certificate) policy_id=certificate

The server typically exposes multiple combinations (None / Sign / SignAndEncrypt× Anonymous / Username / Certificate), and the client selects the appropriate one based on its needs.

Exception​

GetEndpoints Exception Handler (darra::opcua::Exception Inheritance std::runtime_error):

Throwing PointInvalid Content
endpoint_url is emptyException("endpoint_url 不能为空", Status::DarraInvalidArgument)
Returns "Not Good"Exception("GetEndpoints '<url>' failed", <原始状态码>)

The status code is taken as ex.status_code() (raw uint32_t), and the human-readable name is taken as Stack::StatusName(ex.status_code()) — it recognizes names BadCommunicationError such as BadTimeout/ BadServiceUnsupported /; however, the C++ Status enumeration only names a small portion of the raw codes, and values that are not named do not equal any enumeration constants after ex.status() coercion, To determine whether something is good or bad, please use ex.status_code() instead of ex.status().

Next Step​