server_firstSteps.c 939 B

123456789101112131415161718192021222324252627282930313233343536
  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 "ua_config_standard.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.networkLayers = &nl;
  23. config.networkLayersSize = 1;
  24. UA_Server *server = UA_Server_new(config);
  25. UA_StatusCode retval = UA_Server_run(server, &running);
  26. UA_Server_delete(server);
  27. nl.deleteMembers(&nl);
  28. return (int)retval;
  29. }