server_firstSteps.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  3. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  4. */
  5. // This file contains source-code that is discussed in a tutorial located here:
  6. // http://open62541.org/doc/sphinx/tutorial_firstStepsServer.html
  7. #include <stdio.h>
  8. #include <signal.h>
  9. #ifdef UA_NO_AMALGAMATION
  10. # include "ua_types.h"
  11. # include "ua_server.h"
  12. # include "ua_config_standard.h"
  13. # include "networklayer_tcp.h"
  14. #else
  15. # include "open62541.h"
  16. #endif
  17. UA_Boolean running = true;
  18. static void stopHandler(int sig) {
  19. running = false;
  20. }
  21. int main(void) {
  22. signal(SIGINT, stopHandler);
  23. signal(SIGTERM, stopHandler);
  24. UA_ServerConfig config = UA_ServerConfig_standard;
  25. UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
  26. config.networkLayers = &nl;
  27. config.networkLayersSize = 1;
  28. UA_Server *server = UA_Server_new(config);
  29. UA_StatusCode retval = UA_Server_run(server, &running);
  30. UA_Server_delete(server);
  31. nl.deleteMembers(&nl);
  32. return (int)retval;
  33. }