O'Reilly logo

SFML Game Development By Example by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required