9#ifndef __NETWORK_MANAGER_H__
10#define __NETWORK_MANAGER_H__
21#define NM df::NetworkManager::getInstance()
25const std::string DRAGONFLY_PORT =
"9876";
28using delayedMessage = std::tuple<int, char*, size_t>;
29using delayQueue = std::queue<delayedMessage>;
39 std::vector<int> m_sock;
40 std::vector<int> m_delay;
41 std::vector<delayQueue> m_delay_q;
56 bool isValid(std::string event_type)
const override;
60 int setServer(
bool server=
true, std::string port = DRAGONFLY_PORT);
75 int connect(std::string host, std::string port = DRAGONFLY_PORT);
88 int send(
const void *buffer,
int bytes,
int sock = -1);
93 int receive(
void *buffer,
int bytes,
bool leave,
int sock = 0);
126 int sendNow(
const void *buffer,
int bytes,
int sock = 0);
Definition: NetworkManager.h:31
int getMaxConnections() const
Get maximum number of connections.
int send(const void *buffer, int bytes, int sock=-1)
Send bytes from buffer to connected network socket (-1 for all).
int getNumConnections() const
Get number of connected sockets.
int accept()
Accept network connection.
int close(int sock=-1)
Close network connection on indicated socket (-1 for all).
void shutDown() override
Shut down NetworkManager.
int connect(std::string host, std::string port=DRAGONFLY_PORT)
Make network connection to host at port.
bool isValid(std::string event_type) const override
Return true only for network events.
int setDelay(int new_delay, int sock=0)
Set delay amount added to outgoing messages (in ticks).
bool isServer() const
Return true if successufully setup as server, else false.
void setMaxConnections(int new_max_sock)
Set maximum number of connections.
bool isConnected(int sock=-1) const
Check if socket is connected.
int isData(int sock=0) const
Check if network data on indicated socket.
int startUp() override
Start up NetworkManager.
int setServer(bool server=true, std::string port=DRAGONFLY_PORT)
Setup NetworkManager as server (if false, reset to client).
static NetworkManager & getInstance()
Get the one and only instance of the NetworkManager.
int receive(void *buffer, int bytes, bool leave, int sock=0)
Receive from connected network socket (no more than bytes).
int getSocket(int index=0) const
Return socket at indicated index. -1 if out of range.
An animation for a sprite.
Definition: Animation.h:15