Hi all!
I'm doing a server app in C# and have a little problem/question:

I call BeginReceive() method specifying the callback method. In the callback method, I call EndReceive() like this:

Code:
private void OnReceive(IAsyncResult ar)
{
	User user = (User) ar.AsyncState;

	int datalen = user.userSocket.EndReceive(ar);

	Packet datapacket = new Packet();
	datapacket.FromBytes(user.data);

	HandlePacket(datapacket);
}
Now I read some articles and found out that data won't always arrive in packets, since TCP is a streaming protocol.

So my question is: what is the best way to ensure that I receive the full packet before trying to parse them?...

My data packets look like this: 2byte signature, 2bytes defining message type, 2 bytes representing a short value, which tells us how many more bytes the packet has.
So I can easily count the packet size: 6 + (the value that short holds) bytes.

Please tell me if you need some more info.

Thanks in advance!