This isn’t specific to Java, but is there a way to create network lag on localhost or in a LAN for testing purposes? Router, OS, or application settings would be OK.
you can simply put a call to Thread.sleep(randomButNotmuch); before sending a response from the server . That’s how I do it .
NIST is specifically designed for this kind of thing, and does it pretty damn well. Does require you to set up a linux box to route your traffic through though.
Override all InputStream.read(…) and OutputStream.write(…) methods, and sleep once every N bytes.
If you are on linux take a look at the ‘tc’ (traffic control) command, I use it for this sort of thing all the time.
For example to add 100ms delay, 50ms jitter and 1% loss to the eth0 interface you would do the following:
tc qdisc add dev eth0 root netem delay 100ms 50ms loss 1%
And to remove:
tc qdisc del dev eth0 root netem
As an alternative to NIST you may also want to check out Dummynet. Their homepage indicates that it now supports all the major platforms.