Microsoft DirectX 8.1 (C++)

ChatPeer

The ChatPeer sample is similar in form to SimplePeer. Once a player hosts or connects to a session, the players can chat with each other by passing text strings.

Path

Source: (SDK root)\Samples\Multimedia\DirectPlay\ChatPeer

Executable: (SDK root)\Samples\Multimedia\DirectPlay\Bin

User's Guide

Enter the player's name and choose a connection type. You can choose either "Wait for Lobby Connection" or choose a service provider. Use the Multiplayer Games dialog box to either search for an active game to join or to start a new game. After game has been joined or created, the game begins immediately. Other players can join the game at any time. If host migration is on, the host player can also leave at any time since Microsoft® DirectPlay® will automatically migrate the host session to another player.

Programming Notes

The ChatPeer sample is very similar in form to the SimplePeer sample. The ChatPeer differs by letting clients send text string to all players connected to the session. For details, see the "Programming Notes" section of the SimplePeer sample.

When Send is pressed, the SendChatMessage function does the following:

  1. Retrieves the text string from the dialog box.
  2. Fills an application defined structure, GAMEMSG_CHAT. This structure has a message type ID as the first BYTE. This lets the application figure out what type of application message they received, however ChatPeer only uses one application defined message. See StagedPeer for a more complex example of this process.
  3. Fills out a DPN_BUFFER_DESC structure using the GAMEMSG_CHAT buffer.
  4. Calls IDirectPlay8Peer::SendTo() with the DPN_BUFFER_DESC. It passes the DPNID_ALL_PLAYERS_GROUP flag so this message goes to everyone.