samoth, thanks for clearing this up for me. Basically, you are right, IMMEDIATE_PRIORITY sends things right away and doesn't wait for 10ms, it doesn't wait at all. And UNRELIABLE_SEQUENCED is the best one for LAN play, because it doesn't care about lost packets, so if I receive packets in order 5,1,2,6, I just get 5 and 6.
So you are right, I haven't read that.
EDIT:
We still don't know how your apps decide when and how often to call the receive function and that will affect things too.
I was wondering why are you talking about that receiving so much. And I spotted my mistake. Actually this is why my timestamping was totally wrong. Because timestamps actually tell when you RECEIVED the packet, not when it was READY to be received.
And I do all the sending and receiving only when I update the simulation, which is every 50 ms. That's why the timestamping was either 25ms, 24ms, 26ms, 27ms, or 48ms, 2ms, 1ms, 47ms, 48ms, because for example if I start the server app at time = 0 ms, and the client app at time = 25ms, and they all do sending and receiving every 50 ms, this means that even if the packet needs 5ms to arrive, I will still wait another 20 ms until time = 25ms because I haven't called packet->receive()..... :angry: :angry: :angry: :angry: :angry:
while( myApp.myInputManager.isGameRunning() )
{
double current = double( SDL_GetTicks() );
double elapsed = current - previous;
previous = current;
lag += elapsed;
myApp.myInputManager.listenForAllEvents();
while( lag >= MS_PER_UPDATE )
{
myApp.currentState->doServerNetworking(); //Here is where sending and receiving happens. I need to do it outside the loop.
myApp.currentState->updateLogic( myApp.myInputManager );
lag -= MS_PER_UPDATE;
}
myApp.currentState->renderScene( lag / MS_PER_UPDATE );
}
It's really easy to just move the networking out of the inner while-loop, but then even if the server receives the client position earlier, it still has to wait until the simulation is updated, otherwise it doesn't know what position to send back.
EDIT 12093219: Guys, the packets are being sent and received instantly,( 2-3 ms). I just tried at 25 ms and it's working. The problem is that it works 1 out of 10 times. I need to time perfectly when I press 'enter' and start the client app, this way the client and server update loops happen at different times and it works.
But can you propose some other way of synchronizing, other than restarting the client app until it stops to lag?