?/TD>
Microsoft DirectX 9.0

Normal Client/Server Game Play


In Microsoft?DirectPlay? a message is essentially a block of game-related data that is sent from client to server or vice versa. DirectPlay does not specify the contents or format of the data block, it just provides a mechanism to transmit the data. Once the game is underway, each client will normally send a constant stream of messages to the server, and vice versa, for the duration of the game. The primary purpose of these messages is to keep the game state synchronized, so that each user's application displays the same user interface (UI). However, messages can also be used for a variety of other game-specific purposes.

For many games, especially rapidly changing ones, you may have to manage your messaging carefully. DirectPlay throttles outgoing messages to a level that can be handled by the target. You will have be careful that you do not send messages too rapidly, and ensure that the most important messages get through. See Basic Networking for a discussion of how to effectively handle DirectPlay messaging.

The Server Application

To send a message to a client, call IDirectPlay8Server::SendTo. The client will receive a DPN_MSGID_RECEIVE message with the data.

The Client Application

To send a message to the server, call IDirectPlay8Client::Send. The server will receive a DPN_MSGID_RECEIVE message with the data.

Note  DirectPlay does not provide a mechanism for clients to communicate with other clients, only with the server. Any client-client communication must be implemented by the server application.

Using Groups

Many games allow players to be organized into groups. For example, in a squad-based game, every player in the squad could be a member of a group. DirectPlay allows servers in a client/server game to create groups of players. While DirectPlay groups typically correspond to the groups that defined by the game, you are free to create a group for any reason. DirectPlay groups are essentially a way to simplify your messaging. When you have defined a group, you can send a message to every group member with a single IDirectPlay8Server::SendTo call.

To create a DirectPlay group, call IDirectPlay8Server::CreateGroup. Your message handler will then receive a DPN_MSGID_CREATE_GROUP message with the details. The message will include a group identifier (ID) that is used to send messages to the group. Once the group is created, you then add players by calling IDirectPlay8Server::AddPlayerToGroup.

Once the group is established, you can send data to the group by calling IDirectPlay8Server::SendTo, with the dpnid parameter set to the group ID. All group members will then receive a DPN_MSGID_RECEIVE message with the data.

To remove a player from a group, call IDirectPlay8Server::RemovePlayerFromGroup. Finally, when you no longer need the group, you can destroy it by calling IDirectPlay8Server::DestroyGroup.



© 2002 Microsoft Corporation. All rights reserved.