Microsoft DirectX 8.1 (Visual Basic)

Connecting to a Peer-to-Peer Session

Unless you are the session host, you will need to connect your player to the session. To do so, you must have the address of the session host. If your application was connected by a lobby client, you can obtain the host's address by calling DirectPlay8LobbiedApplication.GetConnectionSettings. You can also obtain the address by enumerating the available hosts. The information returned by the enumeration includes each host's addresses, and a DPN_APPLICATION_DESC structure that describes the associated session.

To ask to join a session, call DirectPlay8Peer.SetPeerInfo to set your player's name, and then call DirectPlay8Peer.Connect with the selected host's address to connect to the session.

When a player attempts to join a session, the Microsoft® DirectPlay® calls the host's DirectPlay8Event.IndicateConnect method. To accept the player into the session, set the method's fRejectMsg parameter to False before returning. Setting fRejectMsg to True rejects the request. In either case, the player's DirectPlay8Event.ConnectComplete method will be called with the response. If the host accepted the connection, the hResultCode member of the DPNMSG_CONNECT_COMPLETE type will be set to 0. If the request was rejected or failed for some other reason, hResultCode will be set to an error code.

Once the new player is connected, DirectPlay announces the new player by calling DirectPlay8Event.CreatePlayer for each member of the session, including the host. The lPlayerID parameter contains the player ID that you will use to send messages to that player.