server.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "open62541.h"
  2. #include "open62541-server.h"
  3. #include "open62541-tcp.h"
  4. #include "open62541-ns0-pico.h" // UA_NamespaceZero_Static
  5. #define PORT 1234
  6. #define MAX_CONNECTIONS 1024
  7. int main(int argc, char ** argv) {
  8. // Set up UA_Application
  9. UA_Application *application;
  10. UA_Application_new(&application);
  11. // Set up namespace Zero and typical application parameters
  12. UA_Application_addNamespace(application, 0, &UA_NamespaceZero_Static);
  13. UA_ApplicationDescription *applicationDescription;
  14. UA_Application_new(&applicationDescription);
  15. UA_ApplicationDescription_setApplicationName("Application");
  16. UA_ApplicationDescription_setApplicationUri("http://open62541.org/api-design/");
  17. UA_Application_setVariableNodeNS0(application, UA_APPLICATIONDESCRIPTION_NS0, applicationDescription);
  18. // Set up application specific namespace
  19. UA_Application_addNamespace(application, 1, UA_NULL);
  20. UA_Int32 myInteger = 0;
  21. UA_NodeId myIntegerNode = {1, UA_NODEIDTYPE_NUMERIC, 50};
  22. UA_Application_addVariableNode(application, &myIntegerNode, UA_INT32, &myInteger);
  23. // Set up server with network layer and add application
  24. UA_Server *server;
  25. UA_Server_new(&server);
  26. UA_TcpNetworkLayer_new(&server.configuration.networklayer, PORT, MAX_CONNECTIONS);
  27. UA_Server_addApplication(server, application);
  28. // Run server
  29. UA_Server_start(server);
  30. // Clean up (? first server then application ?)
  31. UA_Server_delete(server);
  32. UA_Application_delete(application);
  33. return 0;
  34. }