I am trying to send a char array to a server and I am not able to send the whole thing. I discovered that I am not receiving that it is sending only the first four packets.
This is the data I want to send in one go.
char msg1[]={0xff,0xfd,0x03,0xff,0xfb,0x18,0xff,0xfb,0x1f,0xff,0xfb,0x20,0xff,0xfb,0x21,0xff,0xfb,0x22,0xff,0xfb,0x27,0xff,0xfd,0x05,0xff,0xfb,0x23};
This is the function I am using to check whether all the bytes have been send or not. and if not. send the rest.
int send_all(int s,char *buf,int *len)
{
int total=0; //total bytes sent
int byteslft= *len; //bytes left to be sent
int n; //value returned by send()
while(total<*len)
{
n=send(s,(buf+total),byteslft,0);
if(n== -1)
break;
total +=n; //total bytes sent will be in total
byteslft -=n; //total bytes left to be sent is stored here
}
*len= total;
return (n==-1)?-1:0;
}
And this how I am trying to send it
len=sizeof (*(arr+i)) ;
if((numbytes=send_all(sockfd,(*(arr+i)),&len))==-1)
{
perror("send");
continue;
}
I have done the connect(),socket(), etc. steps before this just to be clear.
And this is how I've initialized the array of the pointers to the msg array.
char *arr[]={msg1,msg2,msg3,msg4....};
When I debug my program, I see that it is only sending
ff fd 03 ff //message stops sending here
And that's why I'm not getting the required response from the server.
arrayis initialized.arrand how you initialize it.byteslft(pointless abbreviation, btw) you should use that in the while loop. Notice howwhile(bytesleft > 0)reads somewhat better thanwhile(total < *len)?