server_firstSteps.c 969 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 = true;
  14. static void stopHandler(int sig) {
  15. running = false;
  16. }
  17. int main(void) {
  18. signal(SIGINT, stopHandler);
  19. signal(SIGTERM, stopHandler);
  20. UA_ServerConfig config = UA_ServerConfig_standard;
  21. UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
  22. config.logger = Logger_Stdout;
  23. config.networkLayers = &nl;
  24. config.networkLayersSize = 1;
  25. UA_Server *server = UA_Server_new(config);
  26. UA_StatusCode retval = UA_Server_run(server, &running);
  27. UA_Server_delete(server);
  28. nl.deleteMembers(&nl);
  29. return (int)retval;
  30. }