Microsoft DirectX 9.0 SDK Update (Summer 2003) |
AddressOverride
AddressOverride demonstrates how to programmatically provide an address to Microsoft® DirectPlay® in order to host or connect to another session on the network. The alternative is to have DirectPlay display a standard dialog box to ask the user the connection settings. Most games will set addresses directly so that they can provide their own user interface.
Path
Source: (SDK root)\Samples\C++\DirectPlay\AddressOverride
Executable: (SDK root)\Samples\C++\DirectPlay\Bin
User's Guide
The AddressOverride sample displays a dialog box that allows you to select address parameters. To use the dialog box:
- Enter the player's name and session.
- If you want to be a session host, select the Host Session check box.
- Choose a service provider from the Service Provider list.
- Choose an adapter from the Adapter list.
- The remaining steps depend on which service provider you choose.
- If you choose the Transmission Control Protocol/Internet Protocol (TCP/IP) service provider:
- To join a session, select a particular host by entering its Internet Protocol (IP) address and port in the associated edit boxes. You can also have DirectPlay search the local network for available hosts by leaving the IP address and Port boxes blank.
- To host a session, you can specify a port. If you leave the Port box blank, DirectPlay will select a port for you.
- If you choose the model service provider, enter the phone number.
- If you choose the Internetwork Packet Exchange (IPX) service provider, enter the port.
- If you choose the serial service provider, the sample will launch the default DirectPlay dialog box that queries the user for serial settings.
Once you have finished filling in the Address Override dialog box, click OK to start or join a game. This game is similar to SimplePeer. See the SimplePeer user's guide for more details.
Programming Notes
The AddressOverride sample is very similar to the SimplePeer sample. See the Programming Notes section of the SimplePeer sample for details. AddressOverride differs by programmatically specifying an address, rather than having DirectPlay display the default address selection dialog box.
The following list outlines how the AddressOverride sample works. When the OK button is pressed, the sample:
- Determines whether the user wants to host or join a session from the Host Session check box.
- Determines the service provider from the Service Provider list, and selects the appropriate globally unique identifier (GUID).
- Creates an IDirectPlay8Address object called pDeviceAddress.
- Calls that object's IDirectPlay8Address::SetSP method to specify the service provider.
- If the user is hosting a session, creates an IDirectPlay8Address object called pHostAddress. It then calls that object's IDirectPlay8Address::SetSP method to specify the service provider.
- If an adapter was specified, the sample calls the pDeviceAddress object's IDirectPlay8Address::SetDevice to specify the adapter.
The sample then calls IDirectPlay8Address::AddComponent to complete the initialization of the address objects. The details depend on which service provider was selected, and whether the user is joining or hosting a session.
- If the TCP/IP service provider was selected and:
- The user is hosting a session, the user can specify the port.
- If a port was specified, set the pwszName parameter to DPNA_KEY_PORT and call the pDeviceAddress object's IDirectPlay8Address::AddComponent to add the user's port to the address.
- The user is joining a session, the user can specify the host IP address and the port.
- If a host IP address was specified, set the pwszName parameter to DPNA_KEY_HOSTNAME and call the pHostAddress object's IDirectPlay8Address::AddComponent to add the host's IP address to the address object.
- If a port was specified, set the pwszName parameter to DPNA_KEY_PORT and call the pHostAddress object's IDirectPlay8Address::AddComponent method to add the host's port to the address.
- If the IPX service provider was selected and:
- The user is hosting a session, the user must specify a port. Set the pwszName parameter to DPNA_KEY_PORT and call the pDeviceAddress object's IDirectPlay8Address::AddComponent method to add the users port to the address.
- The user is joining a session, the user must specify a port. Set the pwszName parameter to DPNA_KEY_PORT and call the pHostAddress object's IDirectPlay8Address::AddComponent method to add the users port to the address.
- If the modem service provider was selected and the user is joining a session, the user must specify a phone number. Set the pwszName parameter to DPNA_KEY_PHONENUMBER and call the pHostAddress object's IDirectPlay8Address::AddComponent method to add the phone number to the address.
Use the device and host address objects to connect to the session, much like the SimplePeer sample.