mirror of
https://github.com/modelec/cpp-lib.git
synced 2026-03-27 08:59:34 +01:00
initial commit
This commit is contained in:
38
components/TCPClient/include/Modelec/TCPClient.h
Normal file
38
components/TCPClient/include/Modelec/TCPClient.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
|
||||
class TCPClient {
|
||||
private:
|
||||
int clientSocket;
|
||||
sockaddr_in serverAddress{};
|
||||
protected:
|
||||
bool running;
|
||||
|
||||
bool _stoped;
|
||||
|
||||
public:
|
||||
explicit TCPClient(const char* serverIP = "127.0.0.1", int port = 8080);
|
||||
|
||||
void sendMessage(const char* message) const;
|
||||
|
||||
void sendMessage(const std::string& message) const;
|
||||
|
||||
void receiveMessages();
|
||||
|
||||
virtual void start();
|
||||
|
||||
virtual void stop();
|
||||
|
||||
virtual ~TCPClient();
|
||||
|
||||
virtual void handleMessage(const std::string& message);
|
||||
|
||||
bool shouldStop() const;
|
||||
};
|
||||
Reference in New Issue
Block a user