send message of type std::string

This commit is contained in:
ackimixs
2024-03-30 16:54:24 +01:00
parent 7e4585a85c
commit f057ceab77
2 changed files with 8 additions and 2 deletions

View File

@@ -10,14 +10,16 @@
class TCPClient {
int clientSocket;
sockaddr_in serverAddress;
sockaddr_in serverAddress{};
bool running;
public:
TCPClient(const char* serverIP = "127.0.0.1", int port = 8080);
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();
void start();

View File

@@ -25,6 +25,10 @@ void TCPClient::sendMessage(const char* message) const {
send(clientSocket, message, strlen(message), 0);
}
void TCPClient::sendMessage(const std::string& message) const {
send(clientSocket, message.c_str(), message.size(), 0);
}
void TCPClient::receiveMessages() {
char buffer[1024] = {0};
while (running) {