Microsoft DirectX 8.1 (C++)

DataRelay

The DataRelay sample is similar to SimplePeer but differs by sending a packet of data with options specified in the dialog box's user interface.

Path

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

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

User's Guide

Host or connect to a session in the same manner as explained in SimplePeer. When the main dialog box appears, select the target, size, rate, and timeout values. Then click Push to Send. This will send a packet of data to the target at the specified rate and with the specified size. Using the Connection Info drop-down menu, specify a target on which you would like to periodically gather connection information.

Programming Notes

The DataRelay sample is very similar in form to the SimplePeer sample. For details, see the "Programming Notes" section of the SimplePeer sample.

When the Push to Send button is clicked, then a timer is created that goes off every number of milliseconds, as indicated by the user interface (UI).

When the timer goes off, the callback function calls the SendNetworkData function to do the following tasks:

  1. Create an application defined structure.
  2. Create a GAMEMSG_DATA_NODE which is handed off to the application worker thread. That thread processes the node and then updates the UI to show that a packet was sent.
  3. A DPN_BUFFER_DESC structure is filled out passing in a pointer to the application defined structure created above.
  4. The IDirectPlay8Peer::SendTo method is called passing in the DPN_BUFFER_DESC structure.
  5. The event, g_hDPDataAvailEvent, is set telling the worker thread that there is data ready to be processed.

Upon receipt of the g_hDPDataAvailEvent event, the ProcessNetDataProc function calls the ProcessData function which does the following:

  1. Enters the critical section, g_csDataList.
  2. Runs through the linked list, processing each node.
  3. Calls IDirectPlay8Peer::ReturnBuffer, so that DirectPlay can free buffer space that it passed in DPN_MSGID_RECEIVE.

The DirectPlayMessageHandler function handles different kinds of messages such as DPN_MGSID_RECEIVE and DPN_MSGID_SEND_COMPLETE.