All pastes #746017 Raw Edit

Mine

public text v1 · immutable
·published 2007-10-22 21:54 UTC
rendered paste body
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);
	}
}