diff --git a/CMakeLists.txt b/CMakeLists.txt index 096fda9..41a8d97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(TCPSocket VERSION 0.1.2 DESCRIPTION "TCP Socket" LANGUAGES CXX) +project(TCPSocket VERSION 0.1.3 DESCRIPTION "TCP Socket" LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) @@ -9,6 +9,7 @@ set(CMAKE_CXX_STANDARD 17) # Add the source files set(SOURCES src/TCPClient.cpp + src/TCPUtils.cpp ) # Add the header files diff --git a/README.md b/README.md index 58b28d5..339c464 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ git clone https://github.com/modelec/TCPSocketClient.git cd TCPSocketClient mkdir build && cd build cmake .. -make sudo make install ``` @@ -48,6 +47,21 @@ int main() { } ``` +CMakeLists.txt +```cmake +cmake_minimum_required(VERSION 3.20) +project(MyClient) + +set(CMAKE_CXX_STANDARD 17) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(TCPSocket REQUIRED TCPSocket) + +add_executable(MyClient MyClient.cpp) + +target_link_libraries(MyClient TCPSocket) +``` + ### What that do The client start a thread that listen to the server and call the method handleMessage when a message is received. diff --git a/example/client.test.cpp b/example/client.test.cpp index bd4a05f..0239c6d 100644 --- a/example/client.test.cpp +++ b/example/client.test.cpp @@ -1,7 +1,7 @@ #include int main() { - TCPClient client("127.0.0.1", 8082); // Replace "127.0.0.1" with the IP address of your server and 8080 with the port number + TCPClient client("127.0.0.1", 8080); // Replace "127.0.0.1" with the IP address of your server and 8080 with the port number client.start(); diff --git a/include/TCPSocket/TCPUtils.hpp b/include/TCPSocket/TCPUtils.hpp index af27ee0..71b9458 100644 --- a/include/TCPSocket/TCPUtils.hpp +++ b/include/TCPSocket/TCPUtils.hpp @@ -1,37 +1,12 @@ #pragma once #include +#include -inline bool startWith(const std::string& str, const std::string& start) -{ - return str.rfind(start, 0) == 0; -} +inline bool startWith(const std::string& str, const std::string& start); -inline bool endsWith(const std::string& str, const std::string& end) -{ - if (str.length() >= end.length()) - { - return (0 == str.compare(str.length() - end.length(), end.length(), end)); - } - return false; -} +inline bool endsWith(const std::string& str, const std::string& end); -inline bool contains(const std::string& str, const std::string& sub) -{ - return str.find(sub) != std::string::npos; -} +inline bool contains(const std::string& str, const std::string& sub); -inline std::vector split(const std::string& str, const std::string& delimiter) -{ - std::vector tokens; - size_t prev = 0, pos = 0; - do - { - pos = str.find(delimiter, prev); - if (pos == std::string::npos) pos = str.length(); - std::string token = str.substr(prev, pos - prev); - if (!token.empty()) tokens.push_back(token); - prev = pos + delimiter.length(); - } while (pos < str.length() && prev < str.length()); - return tokens; -} \ No newline at end of file +inline std::vector split(const std::string& str, const std::string& delimiter); \ No newline at end of file