Game Development Reference
In-Depth Information
Also, note the maximum packet size and the size of the receive buffer defined just
before the class. These sizes are totally up to you and what you expect to receive in
the way of packets from the remote computers. Your mileage may vary with different
choices, especially in terms of server memory. If you expect to have a few hundred
clients attached, this memory buffer can get pretty big indeed.
Here are the constructors and destructor:
NetSocket::NetSocket()
{
m_sock = INVALID_SOCKET;
m_deleteFlag = 0;
m_sendOfs = 0;
m_timeOut = 0;
m_recvOfs = m_recvBegin = 0;
m_internal = 0;
m_bBinaryProtocol = 1;
}
NetSocket::NetSocket(SOCKET new_sock, unsigned int hostIP)
{
// set everything to zero
m_deleteFlag = 0;
m_sendOfs = 0;
m_timeOut = 0;
m_recvOfs = m_recvBegin = 0;
m_internal = 0;
// check the time
m_timeCreated = timeGetTime();
m_sock = new_sock;
m_ipaddr = hostIP;
// ask the socket manager if the socket is on our internal network
m_internal = g_pSocketManager->IsInternal(m_ipaddr);
setsockopt (m_sock, SOL_SOCKET, SO_DONTLINGER, NULL, 0);
}
NetSocket::~NetSocket()
{
if (m_sock != INVALID_SOCKET)
{
closesocket(m_sock);
 
Search WWH ::




Custom Search