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

Author Topic: Second messagelost on certain computer.  (Read 1875 times)

0 Members and 1 Guest are viewing this topic.

killerloader

  • Newbie
  • *
  • Posts: 28
    • View Profile
Second messagelost on certain computer.
« on: March 03, 2016, 10:35:54 pm »
Basically, i send two messages straight after each other, and the second is not received by the client at all, here is my code:

Quote
         for (int i = 0; i < WC.clients.size(); i++)
         {
            if (WC.clients == nullptr || i == foundEmpty)
               continue;
            mapData.clear();
            mapData << (sf::Int32)2 << (sf::Int32)0 << (sf::Int32)i;
            WC.clients[foundEmpty]->send(mapData);
            cout << "(2) Sending " << i << " to " << foundEmpty << endl;
         }   
foundempty is the ID of the client's socket in the array, this code is on the server and successfully prints:
Quote
(2) Sending 0 to 2
(2) Sending 1 to 2

On the client there is this code to receive the data:

Quote
         sf::Packet recievedata;
         if(WC.socket.receive(recievedata) == sf::Socket::Done)
         {
            sf::Int32 messageType;
            recievedata >> messageType;
            switch (messageType)
            {
            case 2://Other Player
               sf::Int32 oPlayerMessage;
               recievedata >> oPlayerMessage;
               {
                  switch (oPlayerMessage)
                  {
                  case 0://create new player
                  {
                     sf::Int32 OPID;
                     recievedata >> OPID;
                     cout << "Player created: " << OPID << endl;
                     if(WC.otherPlayers[OPID] == nullptr)
                        WC.otherPlayers[OPID] = new otherPlayer(WC);
                     break;
                  }
                  }
               }
            }
         }

This prints:

Quote
Player created: 0

The sockets are non-blocking, and this code runs on a loop.
If i decide to send the information later, it works, it just does not work as it is in this code, i could probably do a workaround by sending all the players in one packet, but i need to know why it's broken before continuing...

Sorry for the messy code, ill try to create a minimal code example later.

Also, these packets successfully get received on my computer at home, but on this computer it does not.
Only one packet gets received.

killerloader

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Second messagelost on certain computer.
« Reply #1 on: March 03, 2016, 10:47:07 pm »
Alright, think i found it, when sending a packet you have to wait for the socket to be ready to send again, so ill just use a hacky while loop until the socket is ready again before sending the second one.

Will make a queue in the future to process packets.