You could give dummynet a shot:
We can control traffic by adding rules that match specific packet data, and then send the packets through a Dummynet pipe with added delay or packet loss. For example, we could add a 100 ms delay to all traffic heading to xkcd.com like so:
$ sudo ipfw pipe 1 config delay 100ms
$ sudo ipfw add 100 pipe 1 ip from any to xkcd.com
00100 pipe 1 ip from any to any dst-ip 126.96.36.199
The first command here configures a Dummynet pipe with id 1, creating the pipe if it did not already exist. The second command creates a rule numbered 100, which matches packets with the desired destination address and routes them through the pipe. Note that any rule that attempts to pass packets through a non-existant pipe will block traffic and throw an error, so do not forget to configure pipes before using them. Using list again allows us to view the updated ruleset.
$ sudo ipfw list
00100 pipe 1 ip from any to 188.8.131.52
65535 allow ip from any to any
Pinging xkcd.com should show a round-trip time of 100 ms plus whatever the actual current latency is across the connection.
$ ping xkcd.com
PING xkcd.com (184.108.40.206): 56 data bytes
64 bytes from 220.127.116.11: icmp_seq=0 ttl=55 time=117.092 ms
64 bytes from 18.104.22.168: icmp_seq=1 ttl=55 time=124.583 ms
64 bytes from 22.214.171.124: icmp_seq=2 ttl=55 time=117.916 ms
64 bytes from 126.96.36.199: icmp_seq=3 ttl=55 time=121.067 ms
In most cases, we would want to simulate a full duplex connection by adding a corresponding rule for packets coming from the remote host, so that the delay is applied in both directions. When we are done playing with our new rule, we can delete it and the pipe as follows.
$ sudo ipfw delete 100
$ sudo ipfw pipe 1 delete
It looks like the dummynet project includes binaries for Windows. To adapt the commands, it should be enough to simply run the
ipfw commands from an elevated command prompt. For example:
ipfw pipe 1 config delay 100ms
ipfw add 100 pipe 1 ip from any to server-ip
ipfw add 101 pipe 1 ip from server-ip to any