Version:

Searching for a Session

Searching for a Session

You search for a session by calling GridMate::StartGridSearch() after the session service has been started. The session settings and configuration are set in the GridMate::SearchParams, which acts as a base class for certain implementations of GridMate::SessionService.


Implementation of GridMate::SessionServiceImplementation of GridMate::SearchParams
GridMate::LANSessionServiceGridMate::LANSearchParams

GridMate::SearchParams

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


ParameterRequiredDefault
m_localMemberYes
m_maxSessionsNo8
m_timeOutMsNo2000
m_versionNo1

GridMate::LANSearchParams

GridMate::LANSessionParams has the following additional parameters.


ParameterRequiredDefaultDescription
m_serverAddressNoEmptyThe address of a server to search for. If empty, a broadcast address is used.
m_serverPortYesThe port that game servers monitor for searches.
m_broadcastFrequencyMsNo1000The interval, in milliseconds, between search broadcast requests.

Search Results

When a search is complete, the OnGridSearchComplete() event is called. The results are found in the GridMate::GridSearch argument.

GridMate::GridSearch contains an array of search results.

To query the size of the array, use GridMate::GridSearch::NumResults().

To query individual results, use GridMate::GridSearch::GetResult().

The GridMate::SearchInfo object contains more details about the session (for example, the number of used and free player slots) and can be used when Joining a Session.

Events

The following table describes GridMate session search events.


EventDescription
OnGridSearchStartA grid search has started.
OnGridSearchCompleteA grid search has finished and contains the results.

Examples

The following example searches for all available sessions. The example assumes that GridMate has been initialized, a session service has been registered, and the class MyClass is listening for session events.

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

    if(gridMate)
    {
        GridMate::LANSearchParams params;
        params.m_serverPort = 20000;
        params.m_localMember = gridMate->GetOnlineService()->GetUser();
        gridMate->StartGridSearch(&params);
    }
}

void MyClass::OnGridSearchComplete(GridMate::GridSearch* search)
{
    if(search->GetNumResults() > 0)
    {
        // Found sessions that match the specified criteria
    }
}