server_discovery.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 <stdio.h>
  9. #include <signal.h>
  10. #include "open62541.h"
  11. UA_Boolean running = true;
  12. static void stopHandler(int sig) {
  13. running = false;
  14. }
  15. int main(void) {
  16. signal(SIGINT, stopHandler);
  17. signal(SIGTERM, stopHandler);
  18. UA_ServerConfig config = UA_ServerConfig_standard;
  19. config.applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER;
  20. config.applicationDescription.applicationUri =
  21. UA_String_fromChars("open62541.example.local_discovery_server");
  22. /* timeout in seconds when to automatically remove a registered server from
  23. * the list, if it doesn't re-register within the given time frame. A value
  24. * of 0 disables automatic removal. Default is 60 Minutes (60*60). Must be
  25. * bigger than 10 seconds, because cleanup is only triggered approximately
  26. * ervery 10 seconds. The server will still be removed depending on the
  27. * state of the semaphore file. */
  28. // config.discoveryCleanupTimeout = 60*60;
  29. UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 4840);
  30. config.networkLayers = &nl;
  31. config.networkLayersSize = 1;
  32. UA_Server *server = UA_Server_new(config);
  33. UA_StatusCode retval = UA_Server_run(server, &running);
  34. UA_String_deleteMembers(&config.applicationDescription.applicationUri);
  35. UA_Server_delete(server);
  36. nl.deleteMembers(&nl);
  37. return (int)retval;
  38. }