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>;
38 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_index=0);
93 int receive(
void *buffer,
int bytes,
bool leave,
int sock_index=0);
139 int sendNow(
const void *buffer,
int bytes,
int sock_index=0);
Definition: NetworkManager.h:31
bool isConnected(int sock_index=0) const
Return true if socket is connected, else false.
int close(int sock_index=0)
Close network connection on indicated socket.
int receive(void *buffer, int bytes, bool leave, int sock_index=0)
Receive from connected network socket (no more than bytes).
int genDataEvents(int sock_index=0) const
If complete network message on indicated socket, (first int is message size, in bytes) generate Event...
int closeAll()
Close all network connections.
int getMaxConnections() const
Get maximum number of connections.
int getNumConnections() const
Get number of connected sockets.
int accept()
Accept network connection.
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 isAnyData() const
Check if data on any connected socket.
bool isServer() const
Return true if successufully setup as server, else false.
int setDelay(int new_delay, int sock_index)
Set delay amount added to outgoing messages (in ticks).
void setMaxConnections(int new_max_sock)
Set maximum number of connections.
int send(const void *buffer, int bytes, int sock_index=0)
Send bytes from buffer to connected network socket.
int startUp() override
Start up NetworkManager.
int getSocket(int sock_index=0) const
Return system socket from socket index, -1 if error.
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 isData(int sock_index=0) const
Check if network data on indicated socket.
An animation for a sprite.
Definition: Animation.h:15