Game Development Reference
In-Depth Information
{
m_HostName = hostName;
m_Port = port;
}
bool Connect();
};
bool ClientSocketManager::Connect()
{
if (!BaseSocketManager::Init())
return false;
RemoteEventSocket *pSocket = GCC_NEW RemoteEventSocket;
if (!pSocket->Connect(GetHostByName(m_HostName), m_Port) )
{
SAFE_DELETE(pSocket);
return false;
}
AddSocket(pSocket);
return true;
}
I haven
ll
see it shortly. All you need to know for now is that RemoteEventSocket is an
extension of the NetSocket class, and it handles all the input and output for the
local game client. In practice, you define whatever socket you want to handle all
your client packets and initialize it in your version of the ClientSocketManager
class.
Here ' s an example of how you might use this class to create a client connection to a
server at shooter.fragfest.com, listening on port 3709:
'
t shown you the RemoteEventSocket class yet, so hang tight because you
'
ClientSocketManager *pClient =
GCC_NEW ClientSocketManager(
shooter.fragfest.com
, 3709);
if (!pClient->Connect())
{
GCC_ERROR(
Couldn
'
t attach to game server.
);
}
Core Server-Side Classes
The server side is a little trickier, but not terribly so. The complexity comes from how
sockets work on the server side. Let ' s review what happens on the server side once
the sockets system is running and the server has a listen socket open.
 
 
Search WWH ::




Custom Search