I need to send data packets in blocks through a socket
. I have a pointer of uchar
with the complete message, and a variable of type int
with the length of it.
The connection of the socket
I have already done perfectly, I just need a help on how to achieve sending the message by blocks of 1024 since I was testing with several examples and with none I could get it.
Something like that is what I'm trying to solve:
BOOL enviarMensaje( UCHAR *sSndData, UINT16 ulSndDataLen)
{
#define SEND_MAX_SIZE 1024
int handle=-1;
short retVal =-1 ;
int totalEnviados=0;
handle=CrearSocket(sTCPAddress,ulTCPPort);
timeout.tv_sec = 2; //segundos
timeout.tv_usec = 100; //microsegundos
setsockopt(handle,SOL_SOCKET,SO_RCVTIMEO,(char*)&timeout,sizeof(timeout));
timeout.tv_sec = 2;
timeout.tv_usec = 100;
setsockopt(handle, SOL_SOCKET,SO_PKTRCVTIMEO,(char*)&timeout,sizeof(timeout));
if(handle >=0)
{
while(totalEnviados<ulSndDataLen){
retVal = send(handle,sSndData,SEND_MAX_SIZE,0);
totalEnviados+= retVal;
}
closesocket(handle);
}
}