implemented client data processing
This commit is contained in:
23
Server.cpp
23
Server.cpp
@@ -50,8 +50,7 @@ void Server::run() {
|
||||
if (_fds[i].fd == _serverSocketFd)
|
||||
handleClientConnection();
|
||||
else
|
||||
// handle existing client incoming data here
|
||||
continue;
|
||||
handleClientData(_fds[i].fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,4 +110,22 @@ void Server::handleClientConnection() {
|
||||
std::cout << "Client <" << newFd << "> Connected" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Server::handleClientData(int fd) {
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
|
||||
// Receive the data
|
||||
ssize_t bytes = recv(fd, buffer, BUFFER_SIZE - 1 , 0);
|
||||
|
||||
// Check if the client disconnected
|
||||
if (bytes <= 0) {
|
||||
std::cout << "Client <" << fd << "> Disconnected" << std::endl;
|
||||
// cleanups here
|
||||
} else {
|
||||
buffer[bytes] = '\0';
|
||||
std::cout << "Client <" << fd << "> Data: " << buffer;
|
||||
|
||||
// parse, check, and handle the received data here
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
#include <poll.h>
|
||||
#include "Client.hpp"
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
class Server {
|
||||
private:
|
||||
@@ -31,6 +32,7 @@ class Server {
|
||||
void bindServerSocket();
|
||||
void addPollfd(int fd, short events, short revents);
|
||||
void handleClientConnection();
|
||||
void handleClientData(int fd);
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user