Designing the client class
With all of the things happening on the client side, be it rendering sprites or playing sounds or processing user input, it only makes sense to have all of the networking code localized inside a single class. This will allow us to communicate with the server quickly and easily. Let's begin designing that class, by first taking a look at some necessary definitions inside the Client.h
header:
#define CONNECT_TIMEOUT 5000 // Milliseconds. class Client; using PacketHandler = std::function< void(const PacketID&, sf::Packet&, Client*)>;
The first definition is the amount of milliseconds that it takes for a client to realize that it's no longer connected to a server. This value can obviously be tweaked at any time. Following that is a definition of a function type that will be used to handle packets on the client side. We're going to be providing the client class with a pointer to a function that is responsible for handling most of the incoming...