Jump to content
  • Advertisement
Sign in to follow this  
Arunas

UDP packet loss simulation

This topic is 3912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I would like to know a way to simulate UDP packet loss when running client and server on same computer.

Share this post


Link to post
Share on other sites
Advertisement
It can be fairly simple. Before every send call, use a conditional statement based on a random number:


float random()
{
return rand() / static_cast<float>(RAND_MAX);
}

void NetworkDealie::tick()
{
// drop one in ten packets, roughly.
if( random() > 0.1 )
{
send(packet);
}
}



Alternatively, you could create a proxy program that the client connects through. This may seem like more work, but at the same time you are taking such "test" code out of your main application, and it leaves a small application you can reuse. Finally it might be easier to use this small app to simulate excessive latency if you want. I'm sure such an application has been written before, you may be able to find one from google.

Share this post


Link to post
Share on other sites
I can not remember which Game Programming Gems book it was (maybe 5 ? I will check) but it came with a good little app for simulating dropped packets.

Edit:
GPG 3
http://www.introgamedev.com/resource_gpg3.html
A Network Monitoring and Simulation Tool - Andrew Kirmse

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!