Microsoft DirectX 8.1 (Visual Basic)

Chat

The Chat sample enables the host and players connected to a session to chat with each other by passing text strings.

Path

Source: (SDK root)\Samples\Multimedia\VBSamples\DirectPlay\Chat

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

User's Guide

Refer to the User's Guide section of the SimplePeer sample.

Programming Notes

The ChatPeer sample is very similar in form to the SimplePeer. ChatPeer differs by enabling clients to send text strings instead of funny faces to all players connected to the session.

When a player types a text string and presses ENTER, the txtSend_KeyPress function does the following:

  1. Retrieves the text string from the dialog box.
  2. Fills out a byte array using the string.
  3. Calls the DirectPlay8Peer.SendTo method and passes the byte array. It sets the DPNID_ALL_PLAYERS_GROUP flag so that this message goes to all of the players.

When a player types a text string and presses Whisper, the cmdWhisper_Click function does the following:

  1. Retrieves the text string from the dialog box.
  2. Fills out a byte array using the string.
  3. Calls the DirectPlay8Peer.SendTo method and passes the byte array. It sets the DPNID of the player so that the message goes only to the person to whom the player is whispering.

The Chat sample handles the DPNMSG_RECEIVE message. On receipt of the message, the DirectPlay8Event_Recieve function:

  1. Checks if this is a Chat message or a Whisper message.
  2. Retrieves the string from the byte array.
  3. Updates the user interface accordingly.

See the DirectPlay8Event objects in the source code for more messages that the Chat sample handles.