should i have more than one packet in a class?
for example in chat app.
theres a:
- list of people in the chat room
- people who joins the room
- people who leaves the room
- messaging system
so i only have one sf::Packet in my class
class ClientManager
{
public:
void sendPacket();
void receivePacket()
{
socket.receive(packet);
}
sf::Packet packet;
}
class MainWindow
{
public:
void leavesTheChatRoom()
{
client.packet << "my name"; // send it, so everybody knows who leaves the room
client.sendPacket();
}
void sendMessage()
{
client.packet << "my message"; // send the message to everybody
client.sendPacket();
}
void receiveMessage()
{
client.receivePacket();
}
private:
ClientManager client;
}
as you can see in the code, 3 functions can use the packet at the same time
- you send a message at the same time someone leaves the room
- you receive a message at the same time you send a message
- etc.
so if thats happens, the packet will have your message and the message of other client and the name in it