mirror of
https://github.com/modelec/TCPSocketClient.git
synced 2026-01-18 16:37:35 +01:00
update v1.0.3
This commit is contained in:
@@ -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
|
||||
|
||||
16
README.md
16
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.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <TCPSocket/TCPClient.hpp>
|
||||
|
||||
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();
|
||||
|
||||
|
||||
@@ -1,37 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
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<std::string> split(const std::string& str, const std::string& delimiter)
|
||||
{
|
||||
std::vector<std::string> 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;
|
||||
}
|
||||
inline std::vector<std::string> split(const std::string& str, const std::string& delimiter);
|
||||
Reference in New Issue
Block a user