Platform SDK: DirectX

Communication Models

This section discusses general principles of communication and maintaining a common state in a network game or similar application. Using DirectPlay, an application can manage its own data using either of the models discussed.

The fundamental concern when writing a networked, multiplayer application is how to propagate state information to all the computers in the session. The state of the session defines what users see on their computers and what actions they can perform. Generally, two things make up the session state: the environment and the individual users or players.

Note  While "user" and "player" are often synonymous in a general sense, it is important to remember that a player is also a logical entity in a DirectPlay application. An application might allow a user to be represented by more than one player.

The environment consists of the objects that the players can interact with or manipulate—for example, a dungeon, a racecourse, or a sequence of chat messages. The environment can also include computer-controlled players.

Within the environment, each player also has a state indicating the player's current properties. These might include position, velocity, energy, armor, and so on.

When a player first joins the session, the session's current state must be downloaded, including the environment and the state of the other players.

Actions performed by users or the natural progression of a game change the state of the session. When this happens, the change must be propagated to the other computers in the session through messages. There are many techniques for updating the session state, but they all depend on sending messages between computers.

Two fundamental ways are available for maintaining state data in a session. The first way is called peer-to-peer. In peer-to-peer sessions, all the computers in the session have the complete state of the environment and of all the players. Any change in state that happens on one computer must be propagated to all the other computers in the session. No one computer is really in charge.

The second way to maintain the session state is called client/server. In client/server sessions, one computer is designated the server, and it maintains the complete state of the game and performs conflict resolution. All the other computers in the session are clients. Each client has only the information that is relevant to that computer and receives that information from the server. When one computer changes something, it propagates the change to the server. The server then determines which clients it must inform of the change.

Using DirectPlay, you can create and manage both peer-to-peer and client/server applications. DirectPlay provides all the tools needed to write a networked, multiplayer application by providing the services to manage players, send messages between players, and automatically propagate the state among all the computers.

The following sections discuss the two modes of communications within DirectPlay sessions: