Microsoft DirectX 8.1 (Visual Basic)

Enumerating Hosts

One way to arrange a session is to have session hosts advertise themselves as available. This type of session is referred to as a broadcast session. Peers or clients can look for a game to join by enumerating the available hosts, selecting one, and then join the game by sending a connection request. See Peer-to-Peer Sessions or Client/Server Sessions for a detailed discussion.

Unlike other enumerations, the information needed to respond to a request for available hosts is not stored on the local computer. Instead, a client or peer must broadcast a request, for instance on their local subnet, and wait for available hosts to respond. Hosts, on the other hand, must wait for these requests, and then respond appropriately. There are thus two slightly different procedures, depending on whether you are a potential session member, or a session host.

The following procedure illustrates how enumerate the available hosts for a peer-to-peer session. The procedure for a client/server session is essentially the same. DirectPlay8Peer.EnumHosts is the method that starts the enumeration. The key parameters to set are ApplicationDesc, Deviceinfo, and AddrHost.

  1. Assign the GUID of the game you are interested in playing to the guidApplication member of the DPN_APPLICATION_DESC type and assign assign it to the ApplicationDesc parameter.
  2. Create a DirectPlay8Address object for your device and assign it to Deviceinfo. This object contains the information needed to make a network connection.
  3. To query a specific computer for available hosts, create a DirectPlay8Address object for the host computer and assign it to pdpaddrHost. If you set leave the object empty, DirectPlay will create an address from the information contained in pdpaddrDeviceinfo. See DirectPlay Addressing for further discussion of address objects. If you are using an IP or IPX service provider, the query will then normally be broadcast to your local subnet.
  4. Call DirectPlay8Peer.EnumHosts.
  5. DirectPlay will then make a series of calls to your message handler's DirectPlay8Event.EnumHostsResponse method, once for each host that responds.

    Examine the information returned to your message handler, select a session, and ask to join it by calling DirectPlay8Peer.Connect.

If you want to be the host of a broadcast session, advertise yourself as available, and wait for queries or connection requests. The following procedure applies to peer-to-peer hosts, but is essentially similar to the procedure for client/server hosts.

  1. Call DirectPlay8Peer.SetPeerInfo to specify the static settings for your player.
  2. Specify the configuration of the game by assigning values in the DPN_APPLICATION_DESC type.
  3. Call DirectPlay8Peer.Host to advertise yourself as a potential host. Set the AppDesc parameter to the DPN_APPLICATION_DESC type defined in the previous step.
  4. Wait for enumeration requests. They will take the form of a call to your message handlers DirectPlay8Peer.EnumHostsQuery method. If you wish to respond to the enumeration request, fill in the DPN_APPLICATION_DESC type and set fRejectMsg to False.
  5. If the peer decides that they would like to join your session, DirectPlay will call your message handler's DirectPlay8Event.IndicateConnect method.

See the Peer-to-Peer Sessions and Client/Server Sessions sections for further discussion of how to arrange and launch a game.