server_firstSteps.c 909 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //This file contains source-code that is discussed in a tutorial located here:
  2. // http://open62541.org/doc/sphinx/tutorial_firstStepsServer.html
  3. #include <stdio.h>
  4. #include <signal.h>
  5. #ifdef UA_NO_AMALGAMATION
  6. # include "ua_types.h"
  7. # include "ua_server.h"
  8. # include "logger_stdout.h"
  9. # include "networklayer_tcp.h"
  10. #else
  11. # include "open62541.h"
  12. #endif
  13. UA_Boolean running;
  14. UA_Logger logger = Logger_Stdout;
  15. static void stopHandler(int signal) {
  16. running = UA_FALSE;
  17. }
  18. int main(void) {
  19. signal(SIGINT, stopHandler);
  20. signal(SIGTERM, stopHandler);
  21. UA_Server *server = UA_Server_new(UA_ServerConfig_standard);
  22. UA_Server_setLogger(server, logger);
  23. UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664));
  24. running = UA_TRUE;
  25. UA_Server_run(server, 1, &running);
  26. UA_Server_delete(server);
  27. printf("Terminated\n");
  28. return 0;
  29. }