Game Development Reference
In-Depth Information
inefficient. The truth is if you use select() , which polls sockets, the real ineffi-
ciency is inside the select statement itself. The other code doesn ' t really take
that much more time. Sockets could also have their delete flags set inside calls to
VHandleInput() or VHandleOutput() , so it makes sense to iterate through
them after those methods are finished.
The code at the end of the method has two kinds of socket shutdown. The first, if the
delete flag is set to 1, removes the socket entirely from the socket manager. This
would occur if the socket were shut down elegantly from both sides, perhaps by trad-
ing an L8R packet or something. The second case allows the NetSocket object to
exist, but the socket handle will be shut down. This allows for a potential reconnec-
tion of a socket if a player drops off the game for a moment but then comes back. If
that happened, the unsent packets still in the NetSocket object would still be ready
to send to the newly reconnected player.
The DoSelect() method is the only thing you need to call in your main loop to
make the entire sockets system work. You
ll want to call this method after you tick
the Event Manager but before updating the game, assuming you are using the socket
system to send events across the network:
'
// allow event queue to process for up to 20 ms
IEventManager::Get()->VUpdate(20);
if (g_pApp->m_pBaseSocketManager)
g_pApp->m_pBaseSocketManager->DoSelect(0); // pause 0 microseconds
g_pApp->m_pGame->VOnUpdate(fTime, fElapsedTime);
The last three methods in the socket manager class are some utility methods. The
first one uses the subnet and subnet mask members to figure out if a particular IP
address is coming from the internal network or from somewhere outside.
bool BaseSocketManager::IsInternal(unsigned int ipaddr)
{
if (!m_SubnetMask)
return false;
if ((ipaddr & m_SubnetMask) == m_Subnet)
return false;
return true;
}
The next two methods wrap the DNS functions you already know how to use:
gethostbyname() and gethostbyaddr() .
Search WWH ::




Custom Search