   Sending large data through TCP winsock
  I've been busy with Winsock for a while now, creating a program that sends snapshots of the desktop through a socket to the client.Everything works when I'm trying to send small packets of data through the socket, stitching the packets back together works! This means I can send small packets of data (the rectangle of which to capture data, small messages etc.) I can even send small images through the socket. The problem is that when I send a relatively large piece of data (+/- 15000 bytes) through the socket, it will only receive 8192 (or 2^13 bytes). After this, the Receive event will not get raised anymore.How do I fix this?this is the code that I use to receive data://'Socket *pSocket', is a pointer to a class that wraps around //the socket part of Winsock//'WSAEVENT hRecvEvent' is the event that indicates if there is any data//to receive//'std::vector<Buffer> *pBufferVector' is a vector of buffers, used to //receive multiple packets of data if there are large packets//'bool &bTotal' is a boolean flag that will be set if the first element//in the vector contains a complete bufferbool ReceiveData(Socket *pSocket, WSAEVENT hRecvEvent, std::vector<Buffer> *pBufferVector, bool &bTotal){Buffer tempBuffer;DWORD dwResult = WSAWaitForMultipleEvents(1, &hRecvEvent, FALSE, 0, FALSE);if (dwResult == 0) {//data is waitingwhile (dwResult == 0) {//loop until all pending data is receivedWSAResetEvent(hRecvEvent);const unsigned int nCurSize = tempBuffer.GetSize();Buffer partialBuffer;SocketReturn socketRes = pSocket->Receive(&partialBuffer, INTERPCMESSAGE_BATCHSIZE, &hRecvEvent);if (socketRes != SOCKETRETURN_FAILURE && partialBuffer.GetSize() != 0) {tempBuffer.Resize(nCurSize + partialBuffer.GetSize());tempBuffer.SetData(partialBuffer.GetBuffer(), nCurSize, partialBuffer.GetSize());}//retrieve result for Receive Event for next while loopdwResult = WSAWaitForMultipleEvents(1, &hRecvEvent, FALSE, 0, FALSE);}//now analyze buffer vectorif (pBufferVector->size() != 0) {//push back current buffer (now >= 2 buffers in vector)pBufferVector->push_back(tempBuffer);std::vector<Buffer>::iterator firstIt = pBufferVector->begin();//get first 4 bytes --> size of messageunsigned int nSize;firstIt->GetData(&nSize, 0, 4);unsigned int nTotalSize = 0;for (std::vector<Buffer>::iterator it = pBufferVector->begin(); it != pBufferVector->end(); it++) {nTotalSize += it->GetSize();if (nSize == nTotalSize) {break;}}if (nSize == nTotalSize) {//somewhere the sizes matched, this means that when we're going to add//all the buffers in the vector, we have a complete messageunsigned int nCounter = 0;for (std::vector<Buffer>::iterator it = pBufferVector->begin() + 1; it != pBufferVector->end(); it++) {const unsigned int nCurFullSize = firstIt->GetSize();const unsigned int nCurSize = it->GetSize();firstIt->Resize(nCurFullSize + nCurSize);firstIt->SetData(it->GetBuffer(), nCurFullSize, nCurSize);nCounter++;if (nCurFullSize + nCurSize == nSize) {break;}}//erase all used bufferspBufferVector->erase(pBufferVector->begin(), pBufferVector->begin() + nCounter);bTotal = true;return true;}bTotal = false;return true;} else {//check if current size matches total size, if so, do nothing//at all, otherwise push on vector stackunsigned int nSize;tempBuffer.GetData(&nSize, 0, 4);pBufferVector->push_back(tempBuffer);if (nSize != tempBuffer.GetSize()) {bTotal = false;return true;}bTotal = true;return true;}}bTotal = false;return true;}And this is the Receive function on my Socket:SocketReturn Socket::Receive(Buffer *pBuffer, unsigned int nBatchSize, WSAEVENT *pRecvEvent){//initialize variablesint nTotalReceived = 0;char *pCurBuf = new char[nBatchSize];int nReceived = 0;do {//receive datanReceived = recv(m_hSocket, pCurBuf, nBatchSize, NULL);if (nReceived > 0) {//connection wasn't closed (or nReceived should be 0)//resize buffer to store datapBuffer->Resize(nTotalReceived + nReceived);//store dataif (!pBuffer->SetData(pCurBuf, nTotalReceived, nReceived)) {delete [] pCurBuf;return SOCKETRETURN_FAILURE;}if (nReceived < int(nBatchSize)) {//got all datadelete [] pCurBuf;return SOCKETRETURN_SUCCESS;}//update total received variablenTotalReceived += nReceived;} else if (nReceived == SOCKET_ERROR) {//check if error was because socket would blockdelete [] pCurBuf;if (WSAGetLastError() == WSAEWOULDBLOCK) {return SOCKETRETURN_WOULDBLOCK;}return SOCKETRETURN_FAILURE;}} while (nReceived > 0);delete [] pCurBuf;return SOCKETRETURN_SUCCESS;}Buffer is a wrapper class for a data buffer that makes it easier for me to move data around.I really hope that somebody can help me out, because I'm stuck for a couple of days now.   
  Do not use "asynchronous" or "event" sockets in WinSock. Both models are inefficient and full of problems. Instead, use either good-old select(), or tie socket operations to an I/O completion port.;  I just wished I heard that a bit earlier. I guess I'll be recoding the entire thing over the next couple of days, thanks for the info anyways!   