Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Packet doesn't get updated when window is displayed  (Read 2245 times)

0 Members and 1 Guest are viewing this topic.

Melwin

  • Newbie
  • *
  • Posts: 1
    • View Profile
Packet doesn't get updated when window is displayed
« on: May 02, 2019, 03:11:47 pm »
I'm trying to make a queue system in my multiplayer game.
I have a local server which is continuously sending the number of clients which are connected to all clients which are connected.

                sf::Packet packet;

                for (int i = 0; i < clientCounter; i++) {
                        packet << clientCounter;
                        if (clients[i].send(packet) == sf::Socket::Status::Done) {
                                std::cout << "Package send..." << std::endl;
                        }
                }

                packet.clear();

The problem now is, that this works perfectly:
void recieveClients() {
        sf::Packet packet;

        socket.receive(packet);
        packet >> playerCount;
        std::cout << playerCount << std::endl;
}

while (!gameRunning) {
        clientReciever = std::thread(&recieveClients);
        clientReciever.join();

        window.clear(sf::Color::White);

        //window.display();
}

But when I remove the comment at //window.display the package which I am recieving is wrong.
Without the window.display every client gets, when I have for example 4 clients connected, the package with the number 4. But with the window.display, client 1 gets the number 1 client 2 gets the number 2 client 3 gets number 3 and client 4 the number 4, you know what I mean.

So it seems that the package doesn't get updated when I'm displaying the window.

 

anything