Hello,
I'm sending a large amount of data through a CSocket, more then 5Mb. Therefore, I splitt the data into chunks of 1024 bytes each. Apparently the connection is done correctly because I can send any data as long as I don't split it. The process of sending the data in chunks is the following:
1. The sender first sends a long with the number of byte that the next package will have.
2. The receiver keeps this value and enters into a while loop of Receive calls until it receives the total amount of bytes.
3. Meanwhile the sender enters on a while loop of Send calls until it sends all the bytes.
The problem is that it sends the first 4 of 5 chuncks of 1024 bytes and then, the send function returns repeatidly the error 10014 in the while loop. Once I mange to send almost almost 2Mb before it returns 10014!!!
The code of Sender part: (NetSocket is a CSocket)
int NetSocket::Send(const void *packet, const size_t &size)
{
size_t totalBytesToSend = size;
size_t totalBytesSent = 0;
do
{
int cbLeftToSend = totalBytesToSend - totalBytesSent;
if(cbLeftToSend > MAX_MESSAGE_LENGTH) cbLeftToSend = MAX_MESSAGE_LENGTH;
int cbBytesSent = 0;
do
{
const char *start = &(((char*)packet)[totalBytesSent]);
cbBytesSent = CSocket::Send(start,cbLeftToSend,0);
if(cbBytesSent == SOCKET_ERROR)
{
netAPIError = GetLastError(); return totalBytesSent;
}
else
{
totalBytesSent += cbBytesSent;
cbLeftToSend -= cbBytesSent;
}
}
while(cbLeftToSend > 0);
}
while(totalBytesSent < totalBytesToSend);
return totalBytesSent;
}
The code on the receiver Socket:
size_t NetSocket::Receive()
{
if(_rcvdPck)
DeleteReceivedPacket();
int pckSize;
int totalRcvdBytes = CSocket::Receive(&pckSize, 4);
totalRcvdBytes = 0;
char *pck = new char[pckSize];
while(totalRcvdBytes < pckSize)
{
int dataRead = CSocket::Receive(&pck[totalRcvdBytes], pckSize - totalRcvdBytes);
totalRcvdBytes += dataRead;
}
_rcvdPck = (NetPacket*)(pck);
return 1; }
Can you see anything wrong ni the code?
Thank you for helping me.