Microsoft DirectX 8.1 (Visual Basic)

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 Microsoft® DirectPlay® calls the server'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, 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.

If the player is successfully added to the session, DirectPlay will call the DirectPlay8Event.CreatePlayer method for the server and all client's with the new player's ID (DPNID).

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 DirectPlay8LobbiedApplication.GetConnectionSettings.

If you not have the address of a session host and you are using either an IP or IPX service provider, you can look for broadcast sessions by calling DirectPlay8Client.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 type that describes the associated session.

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

Microsoft® DirectPlay® will call your DirectPlay8Event.ConnectComplete method with the host's 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.