Selecting a Host for a Peer-to-Peer Session

Although most aspects of peer-to-peer games can be handled by the various users' communicating directly with each other, there are some tasks that must have a single owner. These tasks are handled by the game host. To join a session, you must know the address of the session's host. A common way to select a host is through a lobby server. In that case, when a user's application is connected to the session, the connection settings that you receive with the DPL_MSGID_CONNECT message include the host's address object. To find out who the session host is:

Check the dwFlags member of the DPL_CONNECTION_SETTINGS structure that is returned. If that member is set to DPLCONNECTSETTINGS_HOST, your system is the host.

If the DPLCONNECTSETTINGS_HOST flag is not set, then you can get the address of the host from the pdp8HostAddress member.

You can also create a session, perhaps on a local area network (LAN) subnet, by advertising yourself as a session host. To do so call IDirectPlay8Peer::SetPeerInfo to set the player's name and then call IDirectPlay8Peer::Host to advertise yourself as a potential host. You specify the configuration of the game by assigning values the DPN_APPLICATION_DESC structure that is passed through the pdnAppDesc parameter of IDirectPlay8Peer::Host.

To allow your user to examine the available sessions and hosts, you can enumerate the available hosts by calling IDirectPlay8Peer::EnumHosts. When the user has selected a session, you can request a connection.