Creating a simple communication protocol
Having covered all of the basics, we're finally ready to get designing! The first choice we need to make is which protocol suits our needs better. Losing packets in a real-time application like this is not a tragedy. It's more important that data is sent and received as quickly as possible in order to update the player and all of the entities in the game. Since TCP is a slower protocol and we would not benefit from the extra measures it takes to deliver data in order, the choice is clear. User datagram protocol is the way to go.
Let's flesh out some details of the system we're going to be building by first defining some packet types that are going to be exchanged between the server and client, as well as deciding on the type of the packet identifier. This information will be held inside the PacketTypes.h
header:
using PacketID = sf::Int8; enum class PacketType{ Disconnect = -1, Connect, Heartbeat, Snapshot, Player_Update, Message...