How do I simulate latency and other network disturbances between client and server on same PC

StackOverflow https://stackoverflow.com/questions/17843162

  •  04-06-2022
  •  | 
  •  

Question

I built simple server-client application (windows) using Adobe AIR, based on UDP protocol. What I want to achieve is to test how my application works under network disturbances (latency, packet loss, packet reordering) on a SINGLE PC.

There is plenty of programs for network disturbance simulation, but it looks like they're all made to simulate network disturbances between two PCs, which is not what I need.

Was it helpful?

Solution

If you are using windows, it's not quite possible to create some delay in localhost latency. I came up to this issue this winter and that's how I solved a problem.

All latency logic will be in your AS3 code. On the moment you receive some data (socket data progress event), you create a new Timer with desired delay (or use an existing one) and pass received socket data with the Timer.COMPLETE event. When your timer fires, you can use it's data like you'd normally do without it - you call some needed functions, you process it and do whatever you need. You can also use setTimeout instead of Timer, it doesn't really matter. You can also add some random packet loss by not creating a Timer, so no data would pass through. And you can also use random Timer time so some packets will be reordered.

I won't write any code because the implementation really depends on what you already have now. But I hope this little hint will help you :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top