Microsoft DirectX 8.1 (Visual Basic)

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 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 DirectPlay8Server.SendTo. DirectPlay will call the client's DirectPlay8Event.Receive method with the data.

The Client Application

To send a message to the server, call DirectPlay8Client.Send. DirectPlay will call the server's DirectPlay8Event.Receive method 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. Once you have defined a group, you can send a message to every group member with a single DirectPlay8Server.SendTo call.

To create a DirectPlay group, call DirectPlay8Server.CreateGroup. DirectPlay will call your DirectPlay8Event.CreateGroup method with the details. The notification will include a group ID that is used to send messages to the group. Once the group is created, you then add players by calling DirectPlay8Server.AddPlayerToGroup.

Once the group is established, you can send data to the group by calling DirectPlay8Server.SendTo, with the idSend parameter set to the group ID. DirectPlay will then call the group members' DirectPlay8Event.Receive method with the data.

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