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)
|
if (_fds[i].fd == _serverSocketFd)
|
||||||
handleClientConnection();
|
handleClientConnection();
|
||||||
else
|
else
|
||||||
// handle existing client incoming data here
|
handleClientData(_fds[i].fd);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,4 +110,22 @@ void Server::handleClientConnection() {
|
|||||||
std::cout << "Client <" << newFd << "> Connected" << std::endl;
|
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 <vector>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include "Client.hpp"
|
#include "Client.hpp"
|
||||||
|
#define BUFFER_SIZE 1024
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
private:
|
private:
|
||||||
@@ -31,6 +32,7 @@ class Server {
|
|||||||
void bindServerSocket();
|
void bindServerSocket();
|
||||||
void addPollfd(int fd, short events, short revents);
|
void addPollfd(int fd, short events, short revents);
|
||||||
void handleClientConnection();
|
void handleClientConnection();
|
||||||
|
void handleClientData(int fd);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Reference in New Issue
Block a user