The server class

Now, it's time to take a look at the way things are handled on the other side of the wire. Let's begin by defining some constants:

#define HEARTBEAT_INTERVAL 1000 // Milliseconds.
#define HEARTBEAT_RETRIES 5

Our server application is going to send out heartbeats every second and retry five times before it times out a client. Speaking of clients, there's additional information that we need to keep track of, which calls for a good data structure that holds it all:

struct ClientInfo{ sf::IpAddress m_clientIP; PortNumber m_clientPORT; sf::Time m_lastHeartbeat; sf::Time m_heartbeatSent; bool m_heartbeatWaiting; unsigned short m_heartbeatRetry; unsigned int m_latency; ClientInfo(const sf::IpAddress& l_ip, const PortNumber& l_port, const ...

Get SFML Game Development By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.