The chat client
Our server is quite useless if we don't have the means of connecting to it and sending messages back and forth. In a separate project, let's create a file named Client_Main.cpp and begin writing the client portion of the code, starting with a packet handler:
void HandlePacket(const PacketID& l_id,
sf::Packet& l_packet, Client* l_client)
{
if ((PacketType)l_id == PacketType::Message){
std::string message;
l_packet >> message;
std::cout << message << std::endl;
} else if ((PacketType)l_id == PacketType::Disconnect){
l_client->Disconnect();
}
}As you can see, it's really quite a simple design when we have a proper support class to fall back on. The client responds to two types of packets: messages and disconnects. In case a message pops in, it's extracted and simply printed in the console window. If a disconnect packet arrives from the server, the client's Disconnect method is invoked.
Next, the function...