Share via


Latency Simulation and Bandwidth Usage

To debug and test a networked game, you need to create at least two peers and have them communicate. There are several ways to create multiple peers, including running multiple instances across equal numbers of computers or a mix of computers and Xbox 360 consoles. Most development will take place on a local area network (LAN) where network throughput and quality is not an issue. Networked games that run across the Internet, however, will need to handle a number of issues such as lower bandwidth availability, non-reliable delivery of messages, and firewall and proxy support.

To help developers test networked games over a subnet where you will typically see much lower levels of latency and packet loss than can be expected, the XNA Framework includes a latency and packet loss simulator. This simulator requires no special hardware, extra network cards, or unusual Windows network configurations. You can use the latency simulation capabilities to test techniques, such as client-side prediction, that you might use in your game design.

You can use NetworkSession.SimulatedLatency to set the desired latency, and you can use NetworkSession.SimulatedPacketLoss to set a desired packet loss percentage.

The network simulation respects the SendDataOptions.Reliable and SendDataOptions.InOrder flags. Packets that are sent reliably will never be discarded, no matter how high SimulatedPacketLoss is set. Packets sent without SendDataOptions.InOrder will be delayed by a random value from a bell curve centered on the current SimulatedLatency setting, which has the effect of reordering packets in addition to delaying them. Packets that use SendDataOptions.InOrder will be delayed without any reordering.

For a game to play well over the Internet, it is recommended that you design it to handle up to 0.1 (10%) packet loss, and give it 200 milliseconds of latency.

The XNA Framework also includes performance metrics with the NetworkSession.BytesPerSecondSent and NetworkSession.BytesPerSecondReceived so games can easily measure upstream and downstream bandwidth usage.