|Microsoft DirectX 9.0|
The SimplePeer sample illustrates how to implement a simple peer-to-peer application. After joining or creating a session, the game begins immediately. Other players can join the session at any time.
Source: (SDK root)\Samples\C++\DirectPlay\SimplePeer
Executable: (SDK root)\Samples\C++\DirectPlay\Bin
Enter the player's name and choose a connection type. You can choose Wait for lobby connection or choose a service provider. Use the Multiplayer Games dialog box to search for an active game to join or to start a new game. After the 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 leave at any time because Microsoft?DirectPlay?will automatically migrate the host session to another player.
The InitDirectPlay function does the following:
If the application is lobby launched, the connection settings can be obtained from the lobby client by the ConnectUsingLobbySetting function of the CNetConnectWizard. The CNetConnectWizard class is a helper class. It uses dialog boxes to query the user for information. The ConnectUsingLobbySettings function does the following:
If the connection setting from the lobby client is not provided, the application calls the DoConnectWizard function of the CNetConnectWizard. DoConnectWizard does the following:
The wizard displays the list of the current sessions and allows users to choose a game from the list or create a new one. If Join is clicked, the SessionDlgJoinGame function calls IDirectPlay8Peer::SetPeerInfo to set the player name and IDirectPlay8Peer::Connect to connect to a game. If Create is clicked, the SessionDlgCreateGame function calls IDirectPlay8Peer::SetPeerInfo to set the player's name and IDirectPlay8Peer::Host to begin hosting a game. A DPN_APPLICATION_DESC structure filled with information such as the game name, max player, and the application GUID is passed in the call to Connect.
Once connected, if Wave to other players is clicked, the WaveToAllPlayers function calls IDirectPlay8Peer::SendTo with the dpnid parameter set to DPNID_ALL_PLAYERS_GROUP and the pBufferDesc parameter pointing to a DWORD containing GAME_MSGID_WAVE.
When you click Exit, all the interfaces are cleaned up.