Hello, How are you knowing how many bytes are to be read? I've seen most people throw some random and huge number at it. You might want to try IOCtl with FIONREAD this if you aren't doing it already there:
DWORD dwHowMuch = 0;
IOCtl(FIONREAD, &dwHowMuch); //After this call, dwHowMuch will tell you how many bytes should be read with the Receive call.
Receive(m_szBuffer.GetBuffer(dwHowMuch), /*other params*/);
szBuffer.ReleaseBuffer(-1);
//Now, szBuffer has the data received from the socket.
Note that I'm letting CString do the gruesome stuff of memory allocation and deallocation for me (because CString already has a GetBuffer() method, and I can exploit that here). I'm not proposing this as an excellent solution, but it works and you will be free of any hand-crafted memory management that you might want to implement. I, for once, believe that CString will manage the memory much better than we do (OK, we can write something better, but what the heck... OOP is about reusability and what GetBuffer() has to offer has been good enough for me). Also note that passing a number to CString::GetBuffer() will dynamically 'adjust' the string buffer to hold at least "that much" bytes that was passed to it (mind you this does not include the terminating zero character, but here, we aren't dealing with a string anyways). This will ensure you won't run out of memory and if the previously allocated memory was good enough to hold the data to be currently received, no harm is done! I assumed that you're using MFC, but if you are not, I see your query is already answered. Also, note that you don't 'need' MFC as such if you want to just use CString.
It is a crappy thing, but it's life -^ Carlo Pallini