From dace7a2685fee9e46a095bee01edada743c06092 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 21 Mar 2024 21:43:43 +0100 Subject: [PATCH] readme --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++ example/client.test.cpp | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..7f5dba8 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# TCP Socket Client Lib for Modelec Robot ! + + +### How to install +```bash +git clone https://github.com/modelec/TCPSocketClient.git +cd TCPSocketClient +mkdir build && cd build +cmake .. +make +sudo make install +``` + +### How to use +Create a class that inherit from TCPClient and implement the method handleMessage +```c++ +#include + +class MyClient : public TCPClient { +public: + + explicit MyClient(const char* ip = "127.0.0.1", int port = 8080) : TCPClient(ip, port) {} + + void handleMessage(const std::string& message) override { + std::cout << "Message received : " << message << std::endl; + } +} + +int main() { + MyClient client("127.0.0.1", 8080); + + client.start(); + + while (true) { + std::string message; + std::cout << "Enter message ('quit' to exit): "; + std::getline(std::cin, message); + + if (message == "quit") { + client.stop(); + break; + } + + client.sendMessage(message.c_str()); + } + + return 0; +} +``` + + +### Trubleshooting +If you have an error like when you start the program and it tell you that the Lib.so is not find you need to export : +```bash +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/lib +``` +the path to lib is the folder that the sudo make install command give you. \ No newline at end of file diff --git a/example/client.test.cpp b/example/client.test.cpp index 8bfd8b6..bd4a05f 100644 --- a/example/client.test.cpp +++ b/example/client.test.cpp @@ -1,4 +1,4 @@ -#include +#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