void NetClient::mStartReceive()
{
// Start a loop to read headers
char header[4];
while (recv(mSock, header, 4, 0) > 0) {
NetMessage packet;
// Copy in the header
packet.Copy((unsigned char*)header, 4);
// Get Header Information
packet.Seek(0);
packet.Opcode = packet.Read<unsigned short>();
unsigned int length = packet.Read<unsigned short>() - 4;
unsigned char* data = new unsigned char[length];
while(recv(mSock, (char*)data, length, 0) < length)
{
// Just wait...
}
// Copy in the packet
packet.Seek(0); // Set this to zero, so that when the data gets copied in, it doesnt have the header with it aswell
packet.Copy(data, length);
// Cleanup =)
delete[] data;
packet.Seek(0);
// Call virtual function
DataReceived(packet);
}
}