5 #include <netinet/in.h>
6 #include <sys/socket.h>
13 #include <unordered_map>
15 #define NB_CONNECTION 1000
16 #define READ_BUFFER_SIZE 4096
18 #include "../message/message.hpp"
74 std::unordered_map<int, long long> _clients;
75 std::unordered_map<long long, int> _clientsToFd;
79 std::vector<Message> _msgs;
80 std::unordered_map<int, Message> _partialMsgs;
82 void _acceptNewConnection();
83 bool _receiveClientMsg(
const int& fd);
86 void _clearClient(
int& fd);
91 Server(
const std::string& address,
size_t port);
92 void start(
const size_t& port = 0);
95 const std::function<
void(
long long& clientID,
const Message& msg)>& action);
Class representing a structured message for network communication.
Basic TCP server class using POSIX sockets and select() for multi-client communication.
void sendTo(const Message &message, long long clientID)
void sendToArray(const Message &message, std::vector< long long > clientIDs)
void defineAction(const Message::Type &messageType, const std::function< void(long long &clientID, const Message &msg)> &action)
void sendToAll(const Message &message)
void start(const size_t &port=0)