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

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