?/TD>
Microsoft DirectX 9.0

Connecting to a Client/Server Session


All clients must explicitly join the session by connecting to the host, even if the session has been arranged through a lobby. A connection establishes the client as a member of the session, and provides the host with the information it needs to communicate with the client. The host has the option of accepting or rejecting a connection request.

The Server Application

When a client attempts to join a session, the host receives a DPN_MSGID_INDICATE_CONNECT message. To accept the player into the session, return S_OK. Returning any other value rejects the request. In either case, the client will receive a DPN_MSGID_CONNECT_COMPLETE message that contains your response. You can define a player context value at this time, or wait until you receive a DPN_MSGID_CREATE_PLAYER message. See Using Player Context Values for more discussion of player context values.

If the player is successfully added to the session, the server will receive a DPN_MSGID_CREATE_PLAYER message with the new player's identifier (ID) (DPNID). If you want to define a player context value, and have not yet done so, you must define it before your message handler returns from handling this message. Once it has done so, you cannot change the player context value.

The Client Application

To connect to a session, 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 IDirectPlay8LobbiedApplication::GetConnectionSettings.

If you do not have the address of a session host and you are using either an Internet Protocol (IP) or Internetwork Packet Exchange (IPX) service provider, you can look for sessions by calling IDirectPlay8Client::EnumHosts and enumerating the available hosts. You can also obtain the address by enumerating the available hosts. The information returned by the enumeration includes each host's address, the device use to reach the host, and a DPN_APPLICATION_DESC structure that describes the associated session.

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

Your message handler will receive a DPN_MSGID_CONNECT_COMPLETE message with the host's response. If the host accepted the connection, the hResultCode member of the associated structure will be set to S_OK. If not, hResultCode will be set to DPNERR_HOSTREJECTEDCONNECTION.



© 2002 Microsoft Corporation. All rights reserved.