Multiplayer games enable the game player to enjoy the
cooperation or competition from other players. Before computer networks
were popular, this was normally done by enabling multiple players to
play on a single television screen. Games can enable both players to be
displayed on the screen at the same time and place or can offer multiple
points of view by splitting the screen into multiple areas called split
Many gamers today enjoy the
availability of high speed Internet access. Personal computers and
gaming consoles can connect over the Internet to enable multiple players
to be connected together while playing their games.
XNA Game Studio 4.0
provides the capability to create, find, and connect to network sessions
between Windows PCs using Games for Windows LIVE and Xbox 360s using
Xbox LIVE. The networking APIs that you will use are part of the Microsoft.Xna.Framework.Net assembly and use the namespace of the same name. If your Windows or Xbox 360 project does not currently reference the Microsoft.Xna.Framework.Net
assembly, then add the reference now. You need the reference of the
samples for the remainder of this article. You can also add the using
statement for the Microsoft.Xna.Framework.Net namespace to your Game class. Add the following line of code to your C# file that contains your Game class:
Getting Ready for Networking Development
Building a multiplayer
networked game requires that you have more than one machine that is
running your game. One common development scenario is to build your game
to run on both Xbox 360 and Windows. Because XNA Game Studio supports
building your project for both of these platforms, you can create your
game, deploy the game to your Xbox, and run the Windows version at the
Running an XNA game that uses
networking during development has some requirements for the gamer
profile that is playing the game. On Xbox 360, the gamer profile must
have an XNA Creators Club membership. Because the same membership is
required to do XNA development on Xbox 360, you should already have that
requirement out of the way. The other requirement on Xbox 360 is an
Xbox LIVE Gold membership to connect a Player or Ranked session over the Internet. Only a Silver membership is required if you use SystemLink, which enables multiple machines to connect over a local area network—that is what you normally do when developing your game.
On Windows, only a local Games for Windows LIVE is required for building a game using SystemLink.
If you use a profile that has a Silver or Gold account, you also need
an XNA Creators Club membership. Because you will develop over SystemLink, you should not need a second XNA Creators Club membership. Use a local account or you will get an exception.
To use the networking APIs in XNA, initialize GamerServices.
Add the following code to your Game class constructor:
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
Content.RootDirectory = "Content";
// Initialize GamerServices
If you run the game on Windows, the game runs Game for Windows LIVE (see Figure 1).
Figure 1. Game starting Games for Windows LIVE
Press the Home key to bring up the guide in Game for Windows LIVE (see Figure 2).
Figure 2. Games for Windows LIVE guide
If you already have a profile signed, sign the profile out so that your screen looks like Figure 2.
Now, create a local profile. To do this, select Create New Profile located in the middle button area of the guide.
can use the keyboard, mouse, and Xbox 360 controller to interact with
the Game for Windows LIVE guide. In this article, the samples assume you
are using a wired Xbox 360 controller plugged into your PC.
After you click the Create New Profile button, scroll down to Create a Local Profile link and click the link (see Figure 3).
Figure 3. Creating a local profile in Games for Windows LIVE
Complete the process to
create the new local profile. You can select to have that profile auto
login when you start, which saves you time while you are develop the
game and saves you the step of having to sign in the local profile every
time you start the game.