server_lds.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  3. /*
  4. * Server representing a local discovery server as a central instance.
  5. * Any other server can register with this server (see server_register.c). Clients can then call the
  6. * find servers service to get all registered servers (see client_find_servers.c).
  7. */
  8. #include "open62541.h"
  9. #include <signal.h>
  10. UA_Boolean running = true;
  11. static void stopHandler(int sig) {
  12. running = false;
  13. }
  14. int main(void) {
  15. signal(SIGINT, stopHandler);
  16. signal(SIGTERM, stopHandler);
  17. UA_ServerConfig *config = UA_ServerConfig_new_default();
  18. config->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER;
  19. UA_String_deleteMembers(&config->applicationDescription.applicationUri);
  20. config->applicationDescription.applicationUri =
  21. UA_String_fromChars("urn:open62541.example.local_discovery_server");
  22. config->mdnsServerName = UA_String_fromChars("LDS");
  23. // See http://www.opcfoundation.org/UA/schemas/1.03/ServerCapabilities.csv
  24. config->serverCapabilitiesSize = 1;
  25. UA_String *caps = UA_String_new();
  26. *caps = UA_String_fromChars("LDS");
  27. config->serverCapabilities = caps;
  28. /* timeout in seconds when to automatically remove a registered server from
  29. * the list, if it doesn't re-register within the given time frame. A value
  30. * of 0 disables automatic removal. Default is 60 Minutes (60*60). Must be
  31. * bigger than 10 seconds, because cleanup is only triggered approximately
  32. * ervery 10 seconds. The server will still be removed depending on the
  33. * state of the semaphore file. */
  34. // config.discoveryCleanupTimeout = 60*60;
  35. UA_Server *server = UA_Server_new(config);
  36. UA_StatusCode retval = UA_Server_run(server, &running);
  37. UA_Server_delete(server);
  38. UA_ServerConfig_delete(config);
  39. return (int)retval;
  40. }