Microsoft DirectX 9.0 SDK Update (Summer 2003) |
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 (UI).
Path
Source: (SDK root)\Samples\C++\DirectPlay\DataRelay
Executable: (SDK root)\Samples\C++\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 targetat the rate specifiedwith 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 detailed programming notes, see the Programming Notes section of the SimplePeer sample.
When the Push to Send button is clicked, a timer is created that goes off every number of milliseconds, as indicated by the UI.
When the timer goes off, the callback function calls the SendNetworkData function to do the following tasks.
- Create an application-defined structure.
- 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.
- A DPN_BUFFER_DESC structure is filled out, passing in a pointer to the application-defined structure created above.
- The IDirectPlay8Peer::SendTo method is called, passing in the DPN_BUFFER_DESC structure.
- The event g_hDPDataAvailEvent is set, telling the worker thread that there is data ready to be processed.
On receipt of the g_hDPDataAvailEvent event, the ProcessNetDataProc function calls the ProcessData function, which does the following:
- Enters the critical section, g_csDataList.
- Runs through the linked list, processing each node.
- 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_MSGID_RECEIVE and DPN_MSGID_SEND_COMPLETE.