server_firstSteps.c 927 B

1234567891011121314151617181920212223242526272829303132333435363738
  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;
  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. logger = Logger_Stdout_new();
  23. UA_Server_setLogger(server, logger);
  24. UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664));
  25. running = UA_TRUE;
  26. UA_Server_run(server, 1, &running);
  27. UA_Server_delete(server);
  28. printf("Terminated\n");
  29. return 0;
  30. }