Checking if a UDP packet has arrived?

Blitz3D Forums/Blitz3D Programming/Checking if a UDP packet has arrived?

yours(Posted 2006) [#1]
Hi I am making an online game with UDP, and I seem to have hit a wall. I know that packets can be dropped with UDP, and during the game this is okay for movement because I can implement dead-reckoning. However, what can I do to ensure that packets containing chat messages or game start and end messsages are received?

Like when I am launching the game from the lobby, the host could send a message to the clients signaling the game to begin. Then the host would need to wait until the clients all sent a confirmation message saying that the game start message was received. But if this message is lost, there would need to be a confirmation for the confirmation, starting a vicious cycle. Any ideas on how to solve this?

Thanks


jfk EO-11110(Posted 2006) [#2]
I am working on a UDP system as well.

There are two categories of packets, some that need an acknowledge and some that don't need an acknowledge. Acknowledges and Re-order Messages are the ones that don't need an acknowledge (cause otherwise they would generate an endless loop) Let's call them packet type A (ack) and Type B (no ack) for now.

Every A packet has a serial number. This way the receiver will detect when a packet is missing: when it received packet 3 and then packet 5, it may send a re-order message of type B and ask for packet 4 that is missing.

For every successfully received packet the receiver will immeditalely send back an acknowledge packet of type B. So the server knows the receiver has got it.

Additionally the server may resend the packet if there was no acknowledge in a reasonable time, plus declare the receiver as logged out when it didn't respond for a certain time (eg. 2 Minutes).

Now to go a little further, missing packet are not the only problem, you also have to make sure the packets are not altered. For this purpose you may add a checksum to the header of every packet of type A. The receiver will only send the acknowledge if the integrity check has passed successfully.

For Anti-sabotage and Anti-cheating reasons you may kind of encrypt the checksum and keep the checksum method a secret, so people will fail to manually create cheat-packets.

So whenever a receiver is missing a packet in the serial sequence, or when it received a packet with a bad checksum, it may send a reorder request for the packet in question.

Hope this helps


yours(Posted 2006) [#3]
Thanks alot! This really helps.


Scherererer(Posted 2006) [#4]
or, you could open up a stream on a seperate port that is used for detecting level changes and such which is running on TCP. That way you wouldn't have to do all the checks that TCP does automatically for you. Plus, those messages wouldn't be as "urgent" that they would need to get to you immediately.


Farflame(Posted 2006) [#5]
Or just use Raknet, which does it all for you :)


jfk EO-11110(Posted 2006) [#6]
raknet may be an overkill sometimes. Also, you may want to edit things internally.

>> which does it all <<

not exactly. I was missing several things.


t3K|Mac(Posted 2006) [#7]
or use rottnet. works fine too.