Skip to content

Commit

Permalink
fix(server_ctt): Server will continuously register with the LDS.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelGraf committed Nov 24, 2023
1 parent c0c434d commit 934f7c8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/server_ctt.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,25 @@ notifyState(UA_Server *server, UA_LifecycleState state) {
#endif
}

#ifdef UA_ENABLE_DISCOVERY
static void
registerCallback(UA_Server *server, void *data) {
UA_ClientConfig cc;
memset(&cc, 0, sizeof(UA_ClientConfig));
UA_ClientConfig_setDefault(&cc);
#ifdef UA_ENABLE_ENCRYPTION
UA_ClientConfig_setDefaultEncryption(&cc, certificate, privateKey, NULL, 0, NULL, 0);
UA_String_clear(&cc.clientDescription.applicationUri);
UA_ServerConfig *sc = UA_Server_getConfig(server);
UA_String_copy(&sc->applicationDescription.applicationUri,
&cc.clientDescription.applicationUri);
#endif
UA_Server_registerDiscovery(server, &cc,
UA_STRING("opc.tcp://localhost:4840"),
UA_STRING_NULL);
}
#endif

#ifdef UA_ENABLE_ENCRYPTION
static void
enableNoneSecurityPolicy(UA_ServerConfig *config) {
Expand Down Expand Up @@ -1484,9 +1503,17 @@ int main(int argc, char **argv) {
disableUsernamePasswordAuth(config);
#endif

#ifdef UA_ENABLE_DISCOVERY
/* Add a repeated callback so that the server periodically registers with the Discovery Server. */
UA_UInt64 callbackId;
UA_Server_addRepeatedCallback(server, (UA_ServerCallback)registerCallback, NULL, 600000, &callbackId);
#endif

/* run server */
res = UA_Server_runUntilInterrupt(server);

UA_Server_removeCallback(server, callbackId);

cleanup:
UA_Server_delete(server);

Expand Down

0 comments on commit 934f7c8

Please sign in to comment.