Implementing server

Let's start by taking a look at the second constructor and the destructor of this class:

Server::Server(void(*l_handler)(sf::IpAddress&, const PortNumber&, 
   const PacketID&, sf::Packet&, Server*))
   : m_listenThread(&Server::Listen, this)
{
   // Bind a packet handler function.
   m_packetHandler = std::bind(l_handler, 
     std::placeholders::_1, std::placeholders::_2,
     std::placeholders::_3, std::placeholders::_4,
     std::placeholders::_5);
}

Server::~Server(){ Stop(); }

Nothing too interesting is happening here. The constructor simply binds the provided packet handler function, while the destructor just invokes the Stop method, which we are going to cover shortly. Speaking of binding, we also need a function to handle client timeouts:

void Server::BindTimeoutHandler(void(*l_handler) ...

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.