Version:

Hosting a Session

Hosting a Session

A session can be hosted by calling IGridMate::HostSession() after the session service has been started. The session settings and configuration are set in the GridMate::SessionParams argument, which acts as a base class for certain implementations of GridMate::SessionService.


Implementation of GridMate::SessionServiceImplementation of GridMate::SessionParams
GridMate::LANSessionServiceGridMate::LANSessionParams

GridMate::SessionParams

The following table shows the supported parameters in GridMate::SessionParams.


ParameterRequiredDefaultDescription
m_localMemberYesThis is not required for a LAN session, only for consoles.
m_topologyNoST_PEER_TO_PEERST_CLIENT_SERVER: A client is only connected to the server. ST_PEER_TO_PEER: A client is connected to all other clients.
m_peerToPeerTimeoutNo10000The time without a response, in seconds, after which a peer is disconnected.
m_numPublicSlotsYesThe maximum number of players that can join the session.

GridMate::LANSessionParams

GridMate::LANSessionParams has the following additional parameter.


ParameterRequiredDefaultDescription
m_portNo0The port to monitor for search requests from other clients. If 0, this session is hidden to searches. Otherwise, the port number falls in the range from 1 through 65536.

Events

The following table describes GridMate session service events.


EventDescription
OnSessionCreatedA new session has just been created.
OnMemberJoinedA player has joined the session.
OnMemberLeavingA player has left the session.

Examples

The following example hosts a session. The example assumes that GridMate has been initialized and a session service registered.

bool MyClass::HostSession()
{
    GridMate::IGridMate* gridMate = gEnv->pNetwork->GetGridMate();

    if(gridMate)
    {
        GridMate::LANSessionParams params;
        params.m_topology = Gridmate:ST_CLIENT_SERVER;
        params.m_numPublicSlots = 10;
        params.m_port = 10000;
        params.m_flags = 0;
        params.m_localMember = gridMate->GetOnlineService()->GetUser();

        GridMate::Session session = gridMate->HostSession(&params, GridMate::CarrierDesc());
        if(session != nullptr)
        {
            // Failed to create the session..
            return true;
        }
    }
    return false;
}