Author Topic: Raksleep in receiveloop  (Read 1358 times)

youngssure

  • Not-a-newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Raksleep in receiveloop
« on: November 26, 2014, 02:14:32 AM »
In Windows system,when using the Raknet to receive messages,I find that we

have to call the function of Raksleep(ms) in a receivedloop,as it's showed

below.I doubt if we would delay to get the messages if they comes at the time

when calls Raksleep(ms).How can I avoid this and get the messages immediately

when it comes, is it only reduce the sleep time can help?

sample:
while (1)
{
   for (packet=rakPeer->Receive(); packet; rakPeer->DeallocatePacket

(packet), packet=rakPeer->Receive())
      {
              switch(packet->data[0])
         {
         case ID_CONNECTION_REQUEST_ACCEPTED:
            printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
            break;
                        case ID_NEW_INCOMING_CONNECTION:
            printf("ID_NEW_INCOMING_CONNECTION\n");
            break;
         case ID_NO_FREE_INCOMING_CONNECTIONS:
            printf("ID_NO_FREE_INCOMING_CONNECTIONS\n");
            break;
         case ID_DISCONNECTION_NOTIFICATION:
            printf("ID_DISCONNECTION_NOTIFICATION\n");
            break;
         case ID_CONNECTION_LOST:
            printf("ID_CONNECTION_LOST\n");
            break;
         case ID_CONNECTION_ATTEMPT_FAILED:
            printf("Connection attempt failed\n");
            break;
         default:
            printf("Unknown message type %i\n", packet-

>data[0]);
         }
      }
      RakSleep(30);
}

Tim Auld

  • Not-a-newbie
  • *
  • Posts: 7
  • Karma: 0
    • View Profile
Re: Raksleep in receiveloop
« Reply #1 on: January 22, 2015, 12:19:52 AM »
Perhaps your thread's priority is higher than RakNet's so it never gets any processor time?