Microsoft DirectX 9.0 SDK Update (Summer 2003) |
Initiating a Client/Server Session
A client/server game can be launched through a lobby, or directly by the server application.
The Server Application
Client/server games are often arranged through lobbies. The most straightforward way to launch the server is to implement it as a lobbyable application. This approach provides a way to launch the server, and supports communication between server and lobby during the course of the session. See DirectPlay Lobby for further discussion.
A server can also be directly launched, and then advertise itself as available and wait for clients to connect. See Selecting a Client/Server Host for details.
Once the server application has been launched, it should initialize itself by calling IDirectPlay8Server::Initialize. As with other similar Microsoft® DirectPlay® methods, the primary purpose of initialization is to provide DirectPlay with a pointer to your callback message handler. You should also call IDirectPlay8Server::SetServerInfo to describe the current game. Clients cannot connect to a server until this method has been called.
The Client Application
One of the first steps you should take is to determine whether your game was lobby-launched. To do so, create and initialize a lobbied application object (CLSID_DirectPlay8LobbiedApplication ). When you do so, you pass the object a pointer to your lobbied application message handler. This message handler receives messages directly from the lobbied application object, and indirectly from the lobby client and the lobby.
- If the application was lobby-launched, the IDirectPlay8LobbiedApplication::Initialize method returns a connection handle to the lobby client and a DPL_MSGID_CONNECT message is sent to your lobbied application message handler. The pdplConnectionSettings member of the associated structure points to a DPL_CONNECTION_SETTINGS structure that contains connection information such as an address object for the server.
- If the application was not lobby launched, you will receive neither the connection handle, nor the message. However, if you call IDirectPlay8LobbiedApplication::SetAppAvailable, a lobby client can later connect your running application to a session by sending your lobbied application message handler a DPL_MSGID_CONNECT message.
You should also create and initialize a client object (CLSID_DirectPlay8Client ). This object will be your primary means of communicating with DirectPlay and the server. If you want to have multiple players in the session, you must create a separate instance of this object for each player.