20.User-defined data(Tag) for each host

When RMI or event callback is received, it also receives Proud.HostID that identifies from which host the callback is sent. With this Host ID, you can search for the object of host and handle that object. Most of sample programs of ProudNet are created in that manner. Host Tag is user-defined identifier data besides from the Host ID of local host of other hosts. With the use of Host Tag, you can increase the performance of program as followed.

OnClientJoin(CNetClientInfo* clientInfo)
{
    // If host exit during OnClientJoin function, SetHostTag could fail.
    // So we commend to check as followed.    CNetClientInfo outInfo;
    if(m_client->GetClientInfo(clientInfo->m_HostID,outInfo))
    {
        Host* r = new Host;
        SetHostClientTag(clientInfo->m_HostID, r);
    }
}

DEFRMI_XXX_YYY(MYCLASS)
{
    void* tag = RmiContext.m_hostTag;
    // If SetHostTag is failed, you need check RmiContext.m_hostTag is NULL or not.
    if(tag != NULL)
    {
        Host* obj = (Host*)tag;     // No cost for searching
        obj->Something();
    }
}

Without the use of Host Tag, it would be more like this..

DEFRMI_XXX_YYY(MYCLASS)
{
    Host* obj = Lookup(HostID);  // Cost occurs
    if(obj != NULL)
        obj->Something();
}

그림 20-1Host Tag

You can set Host Tag as followed.

• Proud.CLanClient.SetHostTag

• Proud.CLanServer.SetHostTag

Proud.CNetClient.SetHostTag

Proud.CNetServer.SetHostTag

HostTag can only be received through either Proud.RmiContext.m_hostTag or Proud.CNetPeerInfo.m_hostTag. And most importantly, Host Tag doesn't get synchronized with network thus it will never be transmitted to others!!!