example clParser

This commit is contained in:
ackimixs
2024-05-20 12:43:22 +02:00
parent 852956a913
commit de8aae69ac
2 changed files with 11 additions and 11 deletions

View File

@@ -1,16 +1,20 @@
cmake_minimum_required(VERSION 3.10)
project(MySecondProject)
project(clientExample)
# Find the shared library package
find_package(Modelec COMPONENTS
CLParser
TCPClient
Utils
REQUIRED)
# Define the executable
add_executable(MyExecutable main.cpp)
add_executable(client main.cpp)
# Link the shared library to the executable
target_link_libraries(MyExecutable
target_link_libraries(client
Modelec::CLParser
Modelec::TCPClient
Modelec::Utils
)

View File

@@ -1,19 +1,15 @@
#include <Modelec/TCPClient.h>
#include <Modelec/Utils.h>
#include <Modelec/CLParser.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
int port = 8080;
if (argc >= 2) {
port = std::stoi(argv[1]);
}
CLParser parser(argc, argv);
bool loggerMode = false;
int port = std::stoi(parser.getOption("port", "8080"));
if (argc >= 3) {
loggerMode = Modelec::contains(argv[2], "logger");
}
bool loggerMode = parser.hasOption("logger");
TCPClient client("127.0.0.1", port); // Replace "127.0.0.1" with the IP address of your server and 8080 with the port number