Skip to content
Start free evaluation

pdcomm_opcua_server_create

Function

Creates and binds an in-memory OPC UA server.

int32_t pdcomm_opcua_server_create(pdcomm_opcua_bytes bind_address, const pdcomm_opcua_server_options *options, pdcomm_opcua_handle *out)

Declared in: #include <pdcomm/opcua/pdcomm_opcua.h>

The server owns a standard address space (the Server object, the namespace array with urn:pdcomm:opcua:nodes at index 2 and the standard types). It serves Discovery, Session, View, Attribute, Method, Subscription and MonitoredItem services from memory. It has no external provider, events, history or PubSub (Part 14).

memset(&options, 0, sizeof(options));
options.struct_size = (uint32_t)sizeof(options);
options.version = 1;
status = pdcomm_opcua_server_options_init(&options);
if (status != PDCOMM_OPCUA_OK) { print_error("options", status); goto done; }
options.endpoint.data = (const uint8_t *)argv[2];
options.endpoint.size = strlen(argv[2]);
options.certificate_der.data = certificate;
options.certificate_der.size = certificate_size;
options.private_key_pem.data = key;
options.private_key_pem.size = key_size;
options.trusted_client_der.data = trust;
options.trusted_client_der.size = trust_size;
bind.data = (const uint8_t *)argv[1];
bind.size = strlen(argv[1]);
status = pdcomm_opcua_server_create(bind, &options, &server);
example_wipe(key, key_size); // The SDK copied the identity.

(from examples/opcua/opcua_server.c)

Parameters

NameDescription
bind_addressNumeric socket address to listen on, such as 127.0.0.1:4840, 0.0.0.0:0 or [::1]:4840. Port 0 picks a free port; see pdcomm_opcua_server_local_address().
optionsInitialized options; copied during the call only.
outReceives the server handle.

Returns

#PDCOMM_OPCUA_OK; #PDCOMM_OPCUA_INVALID_INPUT for an invalid address, option, flag, limit, certificate or key, or a missing identity without #PDCOMM_OPCUA_ALLOW_NONE; #PDCOMM_OPCUA_RUNTIME_ERROR when binding fails, the endpoint URL is invalid or the certificate does not match the application URI; #PDCOMM_OPCUA_LIMIT; or #PDCOMM_OPCUA_LICENSE_REQUIRED without an opcua-server license (nothing is bound).

Notes

  • The server serves clients only during pdcomm_opcua_server_poll().